Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send proactive message without saving Conversation reference #1934

Open
ydmztang opened this issue Apr 22, 2022 · 4 comments
Open

Send proactive message without saving Conversation reference #1934

ydmztang opened this issue Apr 22, 2022 · 4 comments
Labels
feature-request A request for new functionality or an enhancement to an existing one. needs-triage The issue has just been created and it has not been reviewed by the team.

Comments

@ydmztang
Copy link

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 ydmztang added feature-request A request for new functionality or an enhancement to an existing one. needs-triage The issue has just been created and it has not been reviewed by the team. labels Apr 22, 2022
@kostyaplis
Copy link
Contributor

kostyaplis commented Nov 9, 2023

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/",
)

@tracyboehrer
Copy link
Member

@kostyaplis This is probably just for Teams?

@kostyaplis
Copy link
Contributor

Yes, for Teams

@Shashank22082002
Copy link

Shashank22082002 commented Feb 12, 2024

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A request for new functionality or an enhancement to an existing one. needs-triage The issue has just been created and it has not been reviewed by the team.
Projects
None yet
Development

No branches or pull requests

4 participants