microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.51k stars 2.45k forks source link

Reply to a conversation thread in teams using Teams bot #6653

Open Ajaykumar661 opened 5 months ago

Ajaykumar661 commented 5 months ago

I have a bot that is created by using Microsoft botframework sdk, I'm trying to find a way to reply to a conversation thread in a teams Channel conversation without being prompted first by a user. So for example given a certain condition (eg. triggered by some event such as time of day, a pull request, etc.) it posts a message in a channel to a particular thread. I have read the documentation on the proactive messaging in teams. I gather that in order to send a message to a teams channel, the bot needs to know the "conversationId" of the user. This information is stored in the conversationreference object, and it gets this from the current conversation. However, in my case I don't have a 'current conservation', because I don't want to just respond to a user, I want to post a reply to a thread proactively. How can I achieve this ?

So far what I tried is to follow this document Graph API, to reply to a conversation using message id using graph api. But since the token is procured on behalf of the user, the reply is posted as a user. Is there a way to post the message reply using graph api by bot ?

Also, I followed a document where the bot can read any messages without being mentioned using @ by following. So I thought we will be getting the user's conversation id in the context object whenever there is a new message in the channel RSC permissions, but it doesn't seems to be working out for me, I'm not sure if I'm missing out on anything

Any guidance on this would be helpful!

### Tasks
Ajaykumar661 commented 5 months ago

@Prasad-MSFT I've seen you answered to questions regarding RSC permissions, mentioning you for better reach and quicker solution....Thanks

tracyboehrer commented 4 months ago

Teams can handle proactive in ways that Azure Bot Service can't. The Bot Framework proactive sample demonstrates the ABS way, which requires a ConversationReference. i.e., The conversation was initiated by the user.

The Teams folks would know more about this, but I did find this: https://learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bot-conversations/bots-conv-proactive?tabs=csharp