My bot has a timer job that checks for something every N minutes and sends a reminder to the user.
Since this is a timer job, that means it's outside any dialog and I don't have access to the session
object.
The code works fine if I create the reminder message like this:
new builder.Message().text("This is a reminder!");
However, this code does not work because the CardAction
requires a session
object as a parameter:
var card = new builder.ThumbnailCard()
.title("Reminder")
.text("Hey it's a reminder.")
.images([exclamation_mark_image_url])
.buttons([builder.CardAction.imBack(null, "check", "Check Overdue")]); //should use `session` instead of null here
The error is a 500 Internal Server Error response from the botframework.com server in chat connector.
This is how I send the generate message when the session
object is not available:
//`msg` is the message with a card generated in the code above
bot.beginDialog(address, dialog_name, msg, function (err) {
//nothing
});
How can I create a ThumbnailCard with a button without a session
object?
What you can do is store the address of the user, and then use
bot.loadSession(storedAddress, function (err, session) {});
This will generate the session object based on the passed in address. In its callback you can use the session object to send messages. I've used the method on a webhook to alert users when certain events are occurring.Depending on how you're storing the timer/alarm, you can also store the user's last
session.message.address
with that data. I haven't worked on the implementation of such a bot, but the next part would be adding a job/method that checks a list of alarms continuously/periodically and then sends the message to the user when their alarm is triggered.