Alexei Masterov
Alexei Masterov

Reputation: 462

Message a single user by user id

I am looking at this sample: https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/python/57.teams-conversation-bot/bots/teams_conversation_bot.py

_message_all_members iterates thorough a list of all members and sends each one a message.

I need a way to send one message to one user. I know their user id. Can you help me write a function that takes a text message and a user id and sends it. Whoever wrote that sample is a pervert, and I can't unwrap all the layers. tc1, tc2. wtf?

Upvotes: 0

Views: 272

Answers (1)

Scott Perham
Scott Perham

Reputation: 2470

I think what you're looking for is "proactive notification", a method to send an activity to a user without the bot first receiving a message from them?

The thing that makes this awkward is that to use the SDK, you need to have a TurnContext that represents the conversation between the bot and the user... this is typically done using the adapter.continue_conversation method which requires you to pass the conversation reference. The conversation reference itself can either be cached from a previous bot message from that user or obtained by creating a new conversation with that user (this would be using the adapter.create_conversation method).

The tc1, tc2 stuff are essentially just references to turn contexts in nested callback methods as this is how create_conversation and continue_conversation work.

There is a specific proactive notification sample that might work better for you here: https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/16.proactive-messages

Upvotes: 1

Related Questions