MS Teams Bot Event Not Fired when message is sent from outside the Teams Bot

Copper Contributor

Hello,

 

I am sending a message on an existing conversation to my MS Teams Chat bot from outside i.e. a Windows Forms Application.

 

 

 

ChannelAccount userAccount = originalActivity.From; 
ChannelAccount botAccount = new ChannelAccount("GenerateReport", "AzureFunction");

var message = new Activity();//Microsoft.Bot.Schema.Activity.CreateEventActivity();
message.Type = ActivityTypes.Message;
message.From = originalActivity.Recipient; //new ChannelAccount("GenerateReport", "AzureFunction");//botAccount;
message.Value = originalActivity; 
((Activity)message).Text = "LongOperationResponse";
message.Recipient = originalActivity.From;// userAccount;
message.ChannelId = originalActivity.ChannelId;
message.Conversation = originalActivity.Conversation;

ResourceResponse response21= await connectorClient.Conversations.SendToConversationAsync((Activity)message);

 

 

 

The message activity is sent successfully and the message appears in the chat bot conversation.

I would also like to somehow trap the event when the above message is received by the ma teams chat bot.
I have attached the following Event handlers in DialogBot class that inherits form ActivityHandler class.
- OnMessageActivityAsync
- OnEventActivityAsync
- OnTurnAsync

 

However, none of the above events handlers get triggered when the message is send from outside the bot using the above logic.

These event handlers get triggered only when user types a message in the chat bot.

Which event should get triggered when an outside message is received by the teams chat bot and how do I handle the event.

Please help.

 

Thanks,
Gagan

 

8 Replies

@gagsbhatnagar - Out side the teams bot mean? How you are sending the message? Could you please explain your scenario in more detail?

@Nikitha-MSFT I am trying to implement the following solution for managing a long running process in MS Teams Bot. However I am getting error while Event Activity Type message back to Bot from Azure Function.

 

https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-long-operations-guidance?view=a...

 

When I send an Message Activity Type message back to Bot from Azure function no event get raised on the Bot side. I expected OnMessageActivityAsync  or OnEventActivityAsync event handlers in DialogBot.cs to be raised when an Activity message gets sent from Azure Function.

 

I tried to send an Activity message to Bot from a sample windows application but still no events were triggered on the Bot side. On both occasions, the message send by Azure Function and sample Windows application appeared in the bot chat window.

 

Let me know if you need more information.

 

Thanks !

@gagsbhatnagar - when you use the message back functionality teams directly send the displaytext mentioned in the card. Are you not receiving the message?

@Nikitha-MSFT I am receiving the message in teams. However, I need to capture the message received in my bot code so that I can process it. Please see the documentation - https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-long-operations-guidance?view=a...
In the above documentation, protected override OnEventActivityAsync is supposed to be invoked when the message is received by the bot.

@gagsbhatnagar - When you are sending message from the azure did you @mention the bot in the message? Are you sending message to team/Group/personal chat between user &bot? Could you please share the repro steps?

 

@Nikitha-MSFT I did not use @mention in the Activity message that I am sending as a personal chat between Bot and user. I tried using @mention in my code but it still did not result in bot event being triggered even though the message that I sent from outside the bot code appeared in the chat bot window.

@gagsbhatnagar - Yes, you can use Message extension.