Reply with “Is Typing” message in Microsoft botframework

放肆的年华 提交于 2019-12-23 16:16:10

问题


I am developing a chatbot using MicrofsoftBotFramework on c#.net and LUIS cognitive services.

I want when user type it should reply as typing or bot is typing..

 public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
            {
                Trace.TraceInformation($"Type={activity.Type} Text={activity.Text}");

                if (activity.Type == ActivityTypes.Message)
                {
                    //await Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync(activity, () => new ContactOneDialog());

                    //Implementation of typing indication
                    ConnectorClient connector = new ConnectorClient(new System.Uri(activity.ServiceUrl));
                    Activity isTypingReply = activity.CreateReply("Shuttlebot is typing...");
                    isTypingReply.Type = ActivityTypes.Typing;
                    await connector.Conversations.ReplyToActivityAsync(isTypingReply);

                    await Conversation.SendAsync(activity, () =>
                    new ExceptionHandlerDialog<object>(new ShuttleBusDialog(), displayException: true));                              
                }
                else
                {
                    HandleSystemMessage(activity);
                }
                var response = Request.CreateResponse(System.Net.HttpStatusCode.OK);
                return response;
            }

This code is working also but it says "TYPING" as animation and goes to next message. But I want it should show my message which I have set as "Shuttlebot is typing...

"

回答1:


Most of the channels natively support "Is Typing" notifications. Just send the Typing Activity as a message:

var reply = activity.CreateReply(String.Empty);
reply.Type = ActivityTypes.Typing;
await activityContext.SendResponse(reply);



回答2:


If you're trying to send the 'typing' status from the controller, the following may be of some help:

var reply = activity.CreateReply(String.Empty);
reply.Type = ActivityTypes.Typing;
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);

Place the above code before the work your controller is trying to do. i.e.

await Conversation.SendAsync(activity, () => new RootDialog());


来源:https://stackoverflow.com/questions/41553491/reply-with-is-typing-message-in-microsoft-botframework

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!