回复Microsoft botframework中的“正在键入”消息

时间:2017-01-09 17:23:19

标签: c# botframework

我正在使用c#.net和LUIS认知服务上的MicrofsoftBotFramework开发一个聊天机器人。

我希望当用户输入时它应该回复为打字或机器人正在输入..

 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正在输入...

的消息

see the image here

2 个答案:

答案 0 :(得分:6)

大多数频道原生支持“正在打字”通知。只需将打字活动作为消息发送:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


    CarsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(cell == nil){
        cell = [[NSBundle mainBundle]loadNibNamed:@"CarsTableViewCell" owner:self options:nil][0];
    }

    cell.imageCar.image = [UIImage imageNamed:[[_arrayCars objectAtIndex:indexPath.row]objectForKey:@"logo"]];
    return cell;
    cell.lblName.text = [[_arrayCars objectAtIndex:indexPath.row]objectForKey:@"name"];
    cell.lblHP.text = [[_arrayCars objectAtIndex:indexPath.row]objectForKey:@"horse_power"];
    cell.lblPrice.text = [[_arrayCars objectAtIndex:indexPath.row]objectForKey:@"price"];

}

答案 1 :(得分:0)

如果您尝试从控制器发送“输入”状态,则以下内容可能会有所帮助:

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

在控制器要执行的工作之前放置上面的代码。即

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