I'm working on a message extension using bot framework v3 (c#). When i install the application in teams and open the bot in 1-1 chat with bot, and send message i'm getting a welcome text.
But i want the welcome text as soon as i open/ access the bot without sending any message to the bot, so i there any way to achieve this.
For welcome text on message event i'm using activity.GetActivityType() == ActivityTypes.Message
So similarly is there any activity type to get bot access event.

- 297
- 3
- 21
1 Answers
If you're using C#, you're listening for the OnMessageActivityAsync event, and implementing your check in there. However, if you want to send the message straight away, without the user having to send one first, you need to also hook into the OnMembersAddedAsync event, and send it there first. For more info, see Send welcome message to users.
In Teams, there's even a modified version of this now, specifically for Teams. I haven't looked into yet myself, but see Subscribe to conversation events for more.
Related to this, especially if the bot is installed into a Team or group chat, you need to do a bit of work in the OnMembersAddedAsync to check if the -bot- is the new member being added, and to make sure you only send 1 message, not multiple (otherwise it can end up sending this 'welcome' a few times). This is shown in the links I provided above. Baically member.Id != turnContext.Activity.Recipient.Id
might need to change, based on what you're trying to do.
hope that helps

- 9,809
- 2
- 10
- 24
-
I have deployed the bot on Azure bot service and when i'm performing any activity it triggers a POST api end point (api/messages). But when i open the app and didn't send any message that api is not getting triggered. I want to send a welcome message as soon as user opens my bot application in MS Teams window. – Mayuresh Jaiswal Jan 20 '20 at 09:18
-
how are you checking if it's getting triggered? Just fyi that the OnMembersAddedAsync only gets fired once, when the user installs the app. If you want it to fire again, uninstall the app, in Teams, and re-install it. I assume you're using App Studio in Teams? If so, you can simply re-install as needed from there. This is all 1-1. For a channel/team, you need to uninstall the bot from the team, then re-install it, but it's actually a little fiddly when it fires here. – Hilton Giesenow Jan 20 '20 at 10:04
-
Its not about install and uninstall the app. If you search app name in top search bar of MS Teams and click the app then it opens the bot page (1-1 chat with bot), that time only i have to send welcome message without sending any message to bot – Mayuresh Jaiswal Jan 20 '20 at 10:33
-
Oh, I see now - you want this to fire -every time- the user goes the Bot chat. This is not possible with Teams - the Bot doesn't get notified every time the user opens the chat history. This is actually a good thing - you'd be sending users a ton of messages, like if they just wanted to see an old message in the chat, or if they click on it accidentally, it would be sending this message every time. What you can possibly do instead is re-send your "welcome" message any time the user says "help" or something similar. – Hilton Giesenow Jan 20 '20 at 11:21
-
@MayureshJaiswal Hilton is correct. It can only be sent the first time. [See here for more details](https://stackoverflow.com/questions/57973996/sending-proactive-messages-to-ms-teams-from-azure-deployed-bot/57980535#57980535) – mdrichardson Jan 20 '20 at 19:42
-
Sure, glad to help. Please go ahead and either "mark as answer" or "upvote". – Hilton Giesenow Jan 21 '20 at 09:00