Creating a thumbnail card with buttons in Bot Framework for Node.js without the session object

和自甴很熟 提交于 2019-12-12 05:47:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/44757727/creating-a-thumbnail-card-with-buttons-in-bot-framework-for-node-js-without-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!