本文介绍了回复“正在输入"; Microsoft botframework中的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在c#.net和LUIS认知服务上使用MicrofsoftBotFramework开发聊天机器人.
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;
}
此代码也可以正常工作,但它会以动画形式显示"TYPING"(打字)并转到下一条消息.但我希望它显示我设置为"Shuttlebot正在输入...
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...
"
推荐答案
大多数渠道本身都支持正在输入"通知.只需将键入活动"作为消息发送:
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);
这篇关于回复“正在输入"; Microsoft botframework中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!