Initiating chat from Bot to user
Hi,
My question is straight - How can we ping user from Bot proactively? Given that user has never pinged the Bot. My user is on skype and Bot is added to user's contacts list.
I have tried to do it but succeeded only when user pings Bot at lease once. After that Bot can ping user using user id, channel id, service URL etc.
I have gone through these questions but still stuck to figure out something concrete -
https://github.com/Microsoft/BotBuilder/issues/1414 https://github.com/Microsoft/BotBuilder/issues/196 https://github.com/Microsoft/BotBuilder/issues/159
In question https://github.com/Microsoft/BotBuilder/issues/1414, dandriscoll talked about Notification systems (e.g. Azure Notification Hubs). But, I am not sure about how to use it. It would be highly appreciable if someone can provide sample arount it. Thanks in advance.
As far as I know, Azure Notification Hubs is suggested because there is an interface between the bot and the user (ProxyWebAPI), but if both your user and your bot is on skype, you can just directly start a conversation with the user.
If you're using C# you can start new conversations from ResumptionCookies. There are some examples here: AlarmBot Create New Conversation Bot Sample
Hi @singhsurya, when the user adds the bot to their contact list, you should receive a ContactRelationUpdate activity containing the user's ID. You must save this ID for use later.
When you want to send a message, you must 1. create a conversation, and then 2. send an activity.
Both steps are illustrated in the CreateNewConversation samples:
- https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/core-CreateNewConversation
- https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-CreateNewConversation
Issue #1414 relates to the Direct Line channel, which does not support CreateNewConversation and leaves it up to the client/app to establish a notification path (like Azure Notification Hubs).
Hi @dandriscoll, thanks for your response. I got your point to save user's id on conversation update event. That can be used later.
But, after a long time interval without any message in conversation, if bot tries to send message to user, it fails. Is there any cancellation token for conversation? I read it somewhere that it is 30 minutes and we can renew it if we want to keep it alive. please confirm. Thanks a lot.
If you're using the Bot Builder SDK, it handles the token refresh for you. This is generally not an issue.
@singhsurya, can you send the ServiceUrl you receive in your ConversationUpdate activity? Is it skype.botframework.com or is it smba.trafficmanager.net (or some other value)?
Hi, @dandriscoll,
The service URL I receive is https://smba.trafficmanager.net and I am not able to ping back from Bot to User after 30 minutes break.
Hi, I'm also trying to achieve the same proactive behavior. Can you explain a bit more about what exactly I need to call (from Bot Builder .NET SDK) to initiate a conversation if I have a user id? As far as I can understand, I need a ServiceUrl to achieve this, but where I get it from? Do I need to save it together with userId when my connector service receives ContactRelationUpdate message?
Thanks
@shigasumi https://docs.botframework.com/en-us/technical-faq/#how-can-i-send-proactive-messages-to-the-user has a link to some samples for proactive messages.
We have our own bot @Wingify that has this feature -> https://github.com/wingify/heybot Particularly, checkout this -> https://github.com/wingify/heybot/blob/master/docs/proactive-messaging.md