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

%3CLINGO-SUB%20id%3D%22lingo-sub-2009390%22%20slang%3D%22en-US%22%3EMS%20Teams%20Bot%20Event%20Not%20Fired%20when%20message%20is%20sent%20from%20outside%20the%20Teams%20Bot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2009390%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20sending%20a%20message%20on%20an%20existing%20conversation%20to%20my%20MS%20Teams%20Chat%20bot%20from%20outside%20i.e.%20a%20Windows%20Forms%20Application.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EChannelAccount%20userAccount%20%3D%20originalActivity.From%3B%20%0AChannelAccount%20botAccount%20%3D%20new%20ChannelAccount(%22GenerateReport%22%2C%20%22AzureFunction%22)%3B%0A%0Avar%20message%20%3D%20new%20Activity()%3B%2F%2FMicrosoft.Bot.Schema.Activity.CreateEventActivity()%3B%0Amessage.Type%20%3D%20ActivityTypes.Message%3B%0Amessage.From%20%3D%20originalActivity.Recipient%3B%20%2F%2Fnew%20ChannelAccount(%22GenerateReport%22%2C%20%22AzureFunction%22)%3B%2F%2FbotAccount%3B%0Amessage.Value%20%3D%20originalActivity%3B%20%0A((Activity)message).Text%20%3D%20%22LongOperationResponse%22%3B%0Amessage.Recipient%20%3D%20originalActivity.From%3B%2F%2F%20userAccount%3B%0Amessage.ChannelId%20%3D%20originalActivity.ChannelId%3B%0Amessage.Conversation%20%3D%20originalActivity.Conversation%3B%0A%0AResourceResponse%20response21%3D%20await%20connectorClient.Conversations.SendToConversationAsync((Activity)message)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20message%20activity%20is%20sent%20successfully%20and%20the%20message%20appears%20in%20the%20chat%20bot%20conversation.%3C%2FP%3E%3CP%3EI%20would%20also%20like%20to%20somehow%20trap%20the%20event%20when%20the%20above%20message%20is%20received%20by%20the%20ma%20teams%20chat%20bot.%3CBR%20%2F%3EI%20have%20attached%20the%20following%20Event%20handlers%20in%20DialogBot%20class%20that%20inherits%20form%20ActivityHandler%20class.%3CBR%20%2F%3E-%20OnMessageActivityAsync%3CBR%20%2F%3E-%20OnEventActivityAsync%3CBR%20%2F%3E-%20OnTurnAsync%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20none%20of%20the%20above%20events%20handlers%20get%20triggered%20when%20the%20message%20is%20send%20from%20outside%20the%20bot%20using%20the%20above%20logic.%3C%2FP%3E%3CP%3EThese%20event%20handlers%20get%20triggered%20only%20when%20user%20types%20a%20message%20in%20the%20chat%20bot.%3C%2FP%3E%3CP%3EWhich%20event%20should%20get%20triggered%20when%20an%20outside%20message%20is%20received%20by%20the%20teams%20chat%20bot%20and%20how%20do%20I%20handle%20the%20event.%3C%2FP%3E%3CP%3EPlease%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3CBR%20%2F%3EGagan%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2009390%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMS%20Teams%20Chat%20Bot%20Events%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2011643%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Teams%20Bot%20Event%20Not%20Fired%20when%20message%20is%20sent%20from%20outside%20the%20Teams%20Bot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2011643%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F909369%22%20target%3D%22_blank%22%3E%40gagsbhatnagar%3C%2FA%3E%26nbsp%3B-%20Out%20side%20the%20teams%20bot%20mean%3F%20How%20you%20are%20sending%20the%20message%3F%20Could%20you%20please%20explain%20your%20scenario%20in%20more%20detail%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2012024%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Teams%20Bot%20Event%20Not%20Fired%20when%20message%20is%20sent%20from%20outside%20the%20Teams%20Bot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2012024%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F590590%22%20target%3D%22_blank%22%3E%40Nikitha-MSFT%3C%2FA%3E%26nbsp%3BI%20am%20trying%20to%20implement%20the%20following%20solution%20for%20managing%20a%20long%20running%20process%20in%20MS%20Teams%20Bot.%20However%20I%20am%20getting%20error%20while%20Event%20Activity%20Type%20message%20back%20to%20Bot%20from%20Azure%20Function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-howto-long-operations-guidance%3Fview%3Dazure-bot-service-4.0%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-howto-long-operations-guidance%3Fview%3Dazure-bot-service-4.0%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20send%20an%20Message%20Activity%20Type%20message%20back%20to%20Bot%20from%20Azure%20function%20no%20event%20get%20raised%20on%20the%20Bot%20side.%20I%20expected%20OnMessageActivityAsync%26nbsp%3B%20or%26nbsp%3BOnEventActivityAsync%20event%20handlers%20in%20DialogBot.cs%20to%20be%20raised%20when%20an%20Activity%20message%20gets%20sent%20from%20Azure%20Function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20to%20send%20an%20Activity%20message%20to%20Bot%20from%20a%20sample%20windows%20application%20but%20still%20no%20events%20were%20triggered%20on%20the%20Bot%20side.%20On%20both%20occasions%2C%20the%20message%20send%20by%20Azure%20Function%20and%20sample%20Windows%20application%20appeared%20in%20the%20bot%20chat%20window.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet%20me%20know%20if%20you%20need%20more%20information.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2017662%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Teams%20Bot%20Event%20Not%20Fired%20when%20message%20is%20sent%20from%20outside%20the%20Teams%20Bot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2017662%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F909369%22%20target%3D%22_blank%22%3E%40gagsbhatnagar%3C%2FA%3E%26nbsp%3B-%20when%20you%20use%20the%20message%20back%20functionality%20teams%20directly%20send%20the%20displaytext%20mentioned%20in%20the%20card.%20Are%20you%20not%20receiving%20the%20message%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2024176%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Teams%20Bot%20Event%20Not%20Fired%20when%20message%20is%20sent%20from%20outside%20the%20Teams%20Bot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2024176%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F590590%22%20target%3D%22_blank%22%3E%40Nikitha-MSFT%3C%2FA%3E%20I%20am%20receiving%20the%20message%20in%20teams.%20However%2C%20I%20need%20to%20capture%20the%20message%20received%20in%20my%20bot%20code%20so%20that%20I%20can%20process%20it.%20Please%20see%20the%20documentation%20-%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-howto-long-operations-guidance%3Fview%3Dazure-bot-service-4.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbot-service%2Fbot-builder-howto-long-operations-guidance%3Fview%3Dazure-bot-service-4.0%3C%2FA%3E%3CBR%20%2F%3EIn%20the%20above%20documentation%2C%20protected%20override%20OnEventActivityAsync%20is%20supposed%20to%20be%20invoked%20when%20the%20message%20is%20received%20by%20the%20bot.%3C%2FLINGO-BODY%3E
Occasional 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.