質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Azure

Azureは、マイクロソフトのクラウド プラットフォームで、旧称は Windows Azureです。PaaSとIaaSを組み合わせることで、 コンピューティング・ストレージ・データ・ネットワーキング・アプリケーションなど多くの機能を持ちます。

Q&A

解決済

1回答

1728閲覧

AzureのWebAppBotで、ブラウザで動かしたときにプロアクティブメッセージが表示できない

退会済みユーザー

退会済みユーザー

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Azure

Azureは、マイクロソフトのクラウド プラットフォームで、旧称は Windows Azureです。PaaSとIaaSを組み合わせることで、 コンピューティング・ストレージ・データ・ネットワーキング・アプリケーションなど多くの機能を持ちます。

0グッド

0クリップ

投稿2019/08/28 07:14

編集2019/08/29 23:06

azureのWebAppBotを使い、ボット起動時に操作なしで選択肢を表示するボットを作成しました。ある程度の動きができ、「Web チャットでテスト」も成功したのでブラウザで実行しましたが、テストとは違ってプロアクティブメッセージが表示されません。

StartUp.cs

C#

1// Copyright (c) Microsoft Corporation. All rights reserved. 2// Licensed under the MIT License. 3 4using Microsoft.AspNetCore.Builder; 5using Microsoft.AspNetCore.Hosting; 6using Microsoft.AspNetCore.Mvc; 7using Microsoft.Bot.Builder; 8using Microsoft.Bot.Builder.Integration.AspNet.Core; 9using Microsoft.BotBuilderSamples.Bots; 10using Microsoft.BotBuilderSamples.Dialogs; 11using Microsoft.Extensions.DependencyInjection; 12using System; 13using System.IO; 14using System.Text; 15using Microsoft.Bot.Builder.AI.QnA; 16using Microsoft.Extensions.Configuration; 17 18namespace Microsoft.BotBuilderSamples 19{ 20 public class Startup 21 { 22 // This method gets called by the runtime. Use this method to add services to the container. 23 public void ConfigureServices(IServiceCollection services) 24 { 25 services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 26 27 // Create the Bot Framework Adapter with error handling enabled. 28 services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); 29 30 // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.) 31 services.AddSingleton<IStorage, MemoryStorage>(); 32 33 // Create the User state. (Used in this bot's Dialog implementation.) 34 services.AddSingleton<UserState>(); 35 36 // Create the Conversation state. (Used by the Dialog system itself.) 37 services.AddSingleton<ConversationState>(); 38 39 // Register LUIS recognizer 40 services.AddSingleton<FlightBookingRecognizer>(); 41 42 // Register the BookingDialog. 43 services.AddSingleton<BookingDialog>(); 44 45 // The MainDialog that will be run by the bot. 46 services.AddSingleton<MainDialog>(); 47 48 // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. 49 services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>(); 50 } 51 52 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 53 public void Configure(IApplicationBuilder app, IHostingEnvironment env) 54 { 55 if (env.IsDevelopment()) 56 { 57 app.UseDeveloperExceptionPage(); 58 } 59 else 60 { 61 app.UseHsts(); 62 } 63 64 app.UseDefaultFiles(); 65 app.UseStaticFiles(); 66 67 app.UseMvc(); 68 } 69 } 70}

DialogAndWelcomeBot.cs

C#

1// Copyright (c) Microsoft Corporation. All rights reserved. 2// Licensed under the MIT License. 3 4using System.Collections.Generic; 5using System.IO; 6using System.Threading; 7using System.Threading.Tasks; 8using Microsoft.Bot.Builder; 9using Microsoft.Bot.Builder.Dialogs; 10using Microsoft.Bot.Schema; 11using Microsoft.Extensions.Logging; 12using Newtonsoft.Json; 13using System; 14using System.Text; 15 16namespace Microsoft.BotBuilderSamples.Bots 17{ 18 public class DialogAndWelcomeBot<T> : DialogBot<T> 19 where T : Dialog 20 { 21 public DialogAndWelcomeBot(ConversationState conversationState, UserState userState, T dialog, ILogger<DialogBot<T>> logger) 22 : base(conversationState, userState, dialog, logger) 23 { 24 File.AppendAllText(@".\text.txt", "DialogAndWelcomeBot" + Environment.NewLine); 25 26 } 27 28 protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) 29 { 30 File.AppendAllText(@".\text.txt", "OnMembersAddedAsync" + Environment.NewLine); 31 32 foreach (var member in membersAdded) 33 { 34 // Greet anyone that was not the target (recipient) of this message. 35 // To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details. 36 if (member.Id != turnContext.Activity.Recipient.Id) 37 { 38 var welcomeCard = CreateAdaptiveCardAttachment(); 39 var response = MessageFactory.Attachment(welcomeCard); 40 await turnContext.SendActivityAsync(response, cancellationToken); 41 await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken); 42 } 43 } 44 } 45 46 // Load attachment from embedded resource. 47 private Attachment CreateAdaptiveCardAttachment() 48 { 49 var cardResourcePath = "CoreBot.Cards.welcomeCard.json"; 50 51 using (var stream = GetType().Assembly.GetManifestResourceStream(cardResourcePath)) 52 { 53 using (var reader = new StreamReader(stream)) 54 { 55 var adaptiveCard = reader.ReadToEnd(); 56 return new Attachment() 57 { 58 ContentType = "application/vnd.microsoft.card.adaptive", 59 Content = JsonConvert.DeserializeObject(adaptiveCard), 60 }; 61 } 62 } 63 } 64 } 65} 66

Cards/welcomeCard.json(テスト用に用意したもので、実際に使う選択肢ではありません)

json

1{ 2 "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", 3 "type": "AdaptiveCard", 4 "version": "1.0", 5 "body": [ 6 { 7 "type": "Image", 8 "url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQtB3AwMUeNoq4gUBGe6Ocj8kyh3bXa9ZbV7u1fVKQoyKFHdkqU", 9 "size": "stretch" 10 }, 11 { 12 "type": "TextBlock", 13 "spacing": "medium", 14 "size": "default", 15 "weight": "bolder", 16 "text": "Welcome to Bot Framework!", 17 "wrap": true, 18 "maxLines": 0 19 }, 20 { 21 "type": "TextBlock", 22 "size": "default", 23 "isSubtle": "yes", 24 "text": "Now that you have successfully run your bot, follow the links in this Adaptive Card to expand your knowledge of Bot Framework.", 25 "wrap": true, 26 "maxLines": 0 27 } 28 ], 29 "actions": [ 30 { 31 "type": "Action.OpenUrl", 32 "title": "Get an overview", 33 "url": "https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0" 34 }, 35 { 36 "type": "Action.OpenUrl", 37 "title": "Ask a question", 38 "url": "https://stackoverflow.com/questions/tagged/botframework" 39 }, 40 { 41 "type": "Action.OpenUrl", 42 "title": "Learn how to deploy", 43 "url": "https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0" 44 } 45 ] 46}

プロアクティブメッセージはDialogAndWelcomeBot.csファイルのOnMembersAddedAsyncメソッドで実行され、Jsonで作成されたカードファイルを読み込んで表示します。DialogAndWelcomeBot.csはStartUp.csファイルのConfigureServicesメソッドで読み込まれます。

動作を調べてみると、どうやらDialogAndWelcomeBot.csファイルが読み込まれた際にOnMembersAddedAsyncメソッドが動いていないようでした。しかしこちらのサイトを見るに、このメソッドはどうあれ起動するように思えます。

テキストボックスに文字を入れて送信するとプロアクティブメッセージとして表示されるはずの文字が表示されるため、プログラムが動作していないわけではないようですが、どうにかして操作しないうちからメッセージを表示したいと思い、相談させていただくことにしました。

どうすれば望み通りプロアクティブメッセージを表示できるようになるでしょうか。
お力添えのほど、よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

自己解決しました。
こちらのページで紹介されているコードを使って成功しました。

投稿2019/09/02 05:23

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問