Botframework-sdk: Push bot automatically to user c#

Created on 12 Dec 2016  路  8Comments  路  Source: microsoft/botframework-sdk

Hi,
Had kept a post here but was closed due to age.
Again posting one for help.

1541

Please refer below.

Is there any way to push the bot to message the user o a particular time of the day?

so that bot sends hi to the user. or any internal clock?

Several people suggested Quartz.net , Hangfire, Azure web jobs. But no one told me how to.
Please provide a working code segment.

All 8 comments

We have a "proactive" azure bot template you might want to look at:

https://docs.botframework.com/en-us/azure-bot-service/templates/proactive/#navtitle

@willportnoy am checking that now, but am confused how can we trigger it at a time? are there no simpler implementations?

Hi @alokraj68,
you can use the template linked by @willportnoy AND the solutions suggested by "other people". You can probably create a Quartz.net (or Hangfire or Azure web) job that triggers every X minute and "push" the message when your condition are matched.

There's no simpler implementation. At least not in the Bot Framework SDK.

@gioffyx I did try hangfire but failed with it. and the template @willportnoy linked seems of another type. I saw many bots that match my requirement but could not find any place where this requirement is addressed

Hi @alokraj68,

If you want the push message (from a timer, etc.) to come in through your bot's messaging endpoint, the sample that @willportnoy linked is the simplest path.

You can build your own webhook system to call a different endpoint on your bot. We don't have a sample for this because there's nothing specific to bots. Simply create a webhook callback, add an appropriate security mode, and configure your external system to call it.

Hi @alokraj68,

here's a possible way of doing what you want:

  • Azure Bot Service bot: the bot needs to ask the user if they want to receive the notification. Upon acceptance you need to write the needed user information in some storage (e.g. Azure Table Storage)
  • TimerTrigger Azure Function: This needs to be a timer trigger function with a Storage Queue output binding, and a Table Storage input binding. At the specified time, the function should get all records from the Storage, and add each individual record to the Queue
  • QueueTrigger Azure Function: This needs to be a QueueTrigger function with a Bot output binding. When triggered, it picks up an item from the queue and sends the message to the bot user in the appropriate channel

If you start from the proactive bot template you'll get some pieces of this solution, that you can change accordingly.
Changes you will likely need:

  • the bot should write to a Table Storage not a Queue. This should be easy to change.
  • the function app needs an additional function, the one that is timertriggered and that reads from the table storage and writes to the queue
  • the payload you save in the table storage might need to change a bit according to your needs. Keep the object that identifies the user/conversation/channel

Sorry, no code samples, I have not tried it yet.

Hope this all makes sense.

@alokraj68, I've just tried the above and it works, so I'm closing this issue. I'll see if I can find time to write a blog post with code samples. If so, I'll post the link here. Feel free to reopen this if you still have issues. Thanks!

@Andrea-Orimoto It would be really great if you could write a blog post on the same. many like me are waiting for that. thank you for finding a solution.

Was this page helpful?
0 / 5 - 0 ratings