Reputation: 530
I guess in short I want the Nodejs equivalent of this SO question in combination with this Github Bot Framework example.
I want to use an Azure Function (I imagine the TimerTrigger Function or maybe a QueueTrigger Function) which will proactively message a given subset of people/addresses who have (naturally) already messaged the bot on a specific platform.
My guess is that I need to use a TimerTrigger and bind it to a storage-type trigger (queueStorage? blogStorage?) that would maintain the list of address/people to message, and then message the Bot via a Direct Line. Though I am completely new to Azure Functions.
To start, I created a bot service on Azure using the Proactive template. In the template they use a QueueTrigger. I’m guessing the function.json for a TimerTrigger would look something like this:
{
"bindings": [
{
"name": "myQueuedAddresses",
"type": "timerTrigger",
"direction": "in",
"queueName": "bot-queue",
"schedule": "0 0 */1 * * *"
},
{
"type": "bot",
"name": "$return",
"direction": "out",
"botId": "botId"
},
{
"type": "http",
"name": "res",
"direction": "out"
}
]
}
To ingest the trigger it would probably be straightforward:
bot.on('trigger', function (addresses) {
addresses.forEach(sendToAddress);
function sendToAddress(item) {
var queuedMessage = item.value;
var reply = new builder.Message()
.address(queuedMessage.address)
.text('This is coming from the trigger: ' + queuedMessage.text);
bot.send(reply);
}
});
But what would the Javascript look like to send the data to the trigger? Or what trigger should I even be using?
Upvotes: 0
Views: 740
Reputation: 26
When using a TimerTrigger Azure function you don't send any data to the trigger function, it will execute automatically based on the set schedule (the cron job setting in your "schedule": "0 0 */1 * * *"). In The proactive bot template: the bot triggers the functions via a queue message, once triggered; the function triggers the Bot via Direct Line.
So if you want to send a daily message to the users (from the Bot) for example, then you can use the proactive bot template, just modify the trigger function side to be a TimeTrigger, and try to send something in the response so your bot knows this is coming from that TimerTrigger. (and if there is no need to write to the queue anymore on the bot side, you can remove that too).
Upvotes: 1