gpt4 book ai didi

javascript - 如何在不为每条消息添加 hubot 的情况下访问 hubot?

转载 作者:行者123 更新时间:2023-11-29 16:48:51 26 4
gpt4 key购买 nike

我正在使用 hubot 和 hubot-fb 适配器开发一个 facebook Messenger 机器人。所有基本设置都已完成并且运行良好。但是,为了与机器人聊天,我需要使用所有命令添加 hubot。在 facebook 聊天的情况下,它没有多大意义。当前的聊天看起来像这样:

user: hubot ping
bot: PONG
user: hubot the rules
bot: 0. A robot may not harm humanity, or, by inaction, allow humanity to come to harm.
1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.
2. A robot must obey any orders given to it by human beings, except where such orders would conflict with the First Law.
3. A robot must p

但是,我希望无需使用“hubot”处理所有消息即可访问我的机器人。我该如何实现?

TIA

最佳答案

您可以使用“听到”方法,而不是“响应”方法。

Hubot 有两种与消息交互的方法:

hear - 只要消息室中的文本与给定的正则表达式匹配,就会调用此方法。在这种情况下不使用机器人的名称。示例:

module.exports = (robot) ->
robot.hear /ping/i, (res) ->
res.send "PONG"

以下消息将导致调用 robot.hear 回调:

  • 如何 ping 服务器

注意:本例中的正则表达式非常简单,可以修改,因此不会为“我如何 ping 服务器”的情况调用回调。

respond - 只有当文本与给定的正则表达式匹配并且紧接在机器人的名称或别名之前时才会调用。示例:

module.exports = (robot) ->
robot.respond /ping/i, (res) ->
res.reply "PONG"

以下消息将导致调用 robot.respond 回调:

  • @Hubot 平
  • 主机ping

由于未使用机器人的名称,因此不会为以下情况调用它。

  • 如何 ping 服务器

参见 Hubot scripting documentation了解更多详情。

关于javascript - 如何在不为每条消息添加 hubot 的情况下访问 hubot?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38158856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com