How to get message id of sent message Bot Framework (Teams channel)?

1.7k views Asked by At

I am using Bot Framework SDK for Javascript. My bot is connected to the Teams channel. Right now I am saving every outgoing and incoming message from my bot to the DB.

But I want also to save reactions of user to my messages. That is why I am using TeamsActivityHandler and onReactionsAdded method (link). In the docs there is written that replyToId field of turnContext is the id of message user is reacting to.

But when I am sending message to the user via turnContext.sendActivity() I don't know the internal id which will be given to this message on Teams side, that is why I can not pair reaction to the message stored in my db.

So my question is, How can I get the id of the message after sending it via turnContext.sendActivity() which will be later send in replyToId field to onReactionsAdded handler?

In other words I want to collect feedback (via reactions) on the messages my bot is sending to the user and save them to my DB (messages and reactions).

2

There are 2 answers

0
Druudik On

Actually it turns out (after some tries) that turnContext.sendActivity() returns ResourceIdentifier which contains one field id and that id is the id which will be given to the message on the Teams side.

EDIT: For some ResourceIdentifier is empty when message sent to Teams is for example hero card. So this does not completly work.

0
Celtic On

You can access the activity param after the await command to get this ID. So if we have our response in a variable reply (could be text, hero card etc...) we can get the ID after the await (inside the override async Task OnMessageActivityAsync method)

await turnContext.SendActivityAsync(reply, cancellationToken);

string responseMsgId = reply.Id;