私のボットのウェブソケットを使ってサーバー上でエコーサービスと通信しようとしています。私はWebSocketSharpアセンブリを使用してWebソケット接続を作成しています。私はボットの中にどんなタイプのユーザをエコーバックしたいのですが、 "ws.OnMessage"イベントを発生させることはありません。私は、コンソールアプリケーション上の接続をテストし、すべてが正常に動作します。私がここで間違っていることを提案してください。続きMSボットフレームワークでウェブソケットとイベントを使用
には、以下の
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity,() => new HumanCollaboratorDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
私MessageControllerである私のHumanCollaboratorDialogクラス
[Serializable]
public class HumanCollaboratorDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
using (var ws = new WebSocket("ws://Some IP addrress:8080/human-collaborator/echo"))
{
ws.OnMessage += async (sender, e) =>
{
try
{
await context.PostAsync(e.Data);
}
catch (Exception ex)
{
await context.PostAsync($"Exception: {ex.Message}");
}
};
ws.ConnectAsync();
var msg = message.Text;
ws.Send(msg);
}
context.Wait(this.MessageReceivedAsync);
}
}
は、あなたがこのサンプルを見てきました。 com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-DirectLineWebSockets –