Microsoft Bot Connector - get activity id from response after sending message

懵懂的女人 提交于 2019-12-24 10:55:23

问题


I'm working on a bot for MS Teams using Microsoft's bot framework (using the .NET API). What I am trying to do right now is to retrieve the Activity.Id of a message the bot has just sent. When the bot receives a message, an Activity.Id is included and I was hoping there was a way to retrieve that when sending a message.

I am currently sending using: var response = connector.Conversations.SendToConversation((Activity)activity);

connector being an instance of Microsoft.Bot.Connector.ConnectorClient

This returns a ResourceResponse, which contains an Id, but this Id does not appear to be in the same format as that of the Activity.Id that comes with a message received.

Does anyone know if it is possible to get this information? Thanks in advance!


回答1:


Take a look at CreateConversationAsync. Here's a code snippet taken from our C# complete sample:

        try
        {
            var conversationResource = await connectorClient.Conversations.CreateConversationAsync(parameters);
            IMessageActivity message = null;

            if (conversationResource != null)
            {
                message = Activity.CreateMessageActivity();
                message.From = new ChannelAccount(botId, botName);
                message.Conversation = new ConversationAccount(id: conversationResource.Id.ToString());
                message.Text = Strings.Send1on1Prompt;
            }

            await connectorClient.Conversations.SendToConversationAsync((Activity)message);
        }
        catch (Exception ex)
        {

        }



回答2:


What about saving the user activity and save the last activity id sent to user, and retrieve it when he sends a message again .to know more about saving user activity see this article Visit: https://blog.botframework.com/2017/05/05/saving-bot-actions-on-azure-sql-server/

I hope this could help you.



来源:https://stackoverflow.com/questions/49457824/microsoft-bot-connector-get-activity-id-from-response-after-sending-message

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