botbuilder-python icon indicating copy to clipboard operation
botbuilder-python copied to clipboard

Send proactive message without saving Conversation reference

Open ydmztang opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. We are trying to build some automation and send messages as a bot. For example, the github PR is open for too long, send bot message to the reviewer.

I see this example to cache the conversation reference: https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/python/16.proactive-messages/bots/proactive_bot.py#L10 However, this implementation just isn't resilient. E.g., what if my bot server crashed, how to I keep the conversation references? We can certainly build something to make it fault tolerant, but that adds unnecessary complexity.

In fact, we do have the user id, but we can't construct a conversation reference from solely the user id + bot id.

Describe the solution you'd like I'd like to have the Bot framework support creating/retrieving conversation reference on the fly given the user id. E.g., conversation_reference = ConversationReference(user_id=user_id, ...)

Describe alternatives you've considered This API seems to be promising: https://docs.microsoft.com/en-us/graph/api/userscopeteamsappinstallation-get-chat?view=graph-rest-1.0&tabs=http However, I can't get the accessToken from the SDK (it requires the TurnContext, which is again a problem for proactive scenarios)

Additional context

ydmztang avatar Apr 22 '22 00:04 ydmztang

the following snippet works for me to send proactive messages to the user:

config = DefaultConfig()
adapter = CloudAdapter(ConfigurationBotFrameworkAuthentication(config))

recipient = ChannelAccount(id=${aadObjectId})
bot = ChannelAccount(id=config.APP_ID)

activity_reply = Activity(
        type=ActivityTypes.message,
        channel_id="msteams",
        from_property=bot,
        recipient=recipient,
        text="Hello!",
)
conversation_params = ConversationParameters(
        bot=bot,
        members=[recipient],
        activity=activity_reply,
        channel_data={"tenant": {"id": "${tenantID}"}},
)
await adapter.create_conversation(
        bot_app_id=config.APP_ID,
        callback=lambda turn_context: turn_context.send_activity(activity_reply),
        conversation_parameters=conversation_params,
        channel_id="msteams",
        service_url="https://smba.trafficmanager.net/teams/",
)

kostyaplis avatar Nov 09 '23 04:11 kostyaplis

@kostyaplis This is probably just for Teams?

tracyboehrer avatar Feb 06 '24 19:02 tracyboehrer

Yes, for Teams

kostyaplis avatar Feb 06 '24 23:02 kostyaplis

@kostyaplis Can you tell how to modify this to send a reply message on a post on teams proactively. (If I store the initial ids like ActivityId and any other attribute if needed in some database)

Shashank22082002 avatar Feb 12 '24 14:02 Shashank22082002