在Bot Framework for Node.js中创建带有按钮的缩略图卡,而没有会话对象 [英] Creating a thumbnail card with buttons in Bot Framework for Node.js without the session object

查看:88
本文介绍了在Bot Framework for Node.js中创建带有按钮的缩略图卡,而没有会话对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器人有一个计时器作业,该作业每N分钟检查一次并向用户发送提醒.

My bot has a timer job that checks for something every N minutes and sends a reminder to the user.

由于这是计时器工作,这意味着它在任何对话框之外,并且我无权访问session对象.

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!");

但是,此代码不起作用,因为CardAction需要一个session对象作为参数:

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

该错误是聊天连接器中botframework.com服务器发出的500 Internal Server Error响应.

The error is a 500 Internal Server Error response from the botframework.com server in chat connector.

session对象不可用时,这是我发送生成消息的方式:

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
});

如何使用不带session对象的按钮创建ThumbnailCard?

How can I create a ThumbnailCard with a button without a session object?

推荐答案

您可以做的是存储用户的地址,然后使用bot.loadSession(storedAddress, function (err, session) {});.这将基于传入的地址生成会话对象.在其回调中,您可以使用会话对象发送消息.我已经使用了Webhook上的方法来在发生某些事件时提醒用户.

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.

根据您存储计时器/警报的方式,还可以将用户的最后一个session.message.address与该数据一起存储.我还没有实现这种机器人的工作,但是下一部分将添加一个作业/方法,该方法可以连续/定期检查警报列表,然后在触发警报时将消息发送给用户.

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.

这篇关于在Bot Framework for Node.js中创建带有按钮的缩略图卡,而没有会话对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆