hubot - 如何在 hubot 脚本中获取适配器名称?

标签 hubot

Hubot可以支持不同的适配器,如Shell/IRC/XMPP。

如果在环境变量HUBOT_ADAPTER中设置了适配器,则可以检查process.env.HUBOT_ADAPTER

if process.env.HUBOT_ADAPTER is "shell"
   msg.send "This is Shell adapater"

但它也支持使用选项--adapter,以及如何在 hubot 脚本中检测到这一点。

我想根据适配器编写不同的逻辑,例如聊天室、用户ID。

否则我需要为不同的适配器准备单独的脚本。

最佳答案

从github问题中得到了两个建议https://github.com/github/hubot/issues/647

[更新]此问题已在源代码 robot.coffee 中修复通过添加adapterName ,所以你可以检查robot.adapterName自版本 2.7.2 起,请参阅 changes

嗅探,可以通过adapter中的特殊信息进行检查,并可能在下面检查我的环境 shell , xmpp , irc

robot.respond /adapter$/i, (msg) ->
    #console.log "adapter", robot.adapter
    if robot.adapter.client?
        if robot.adapter.client.preferredSaslMechanism?
            msg.send "this is xmpp adapter"
    if robot.adapter.bot?
        if robot.adapter.bot.opt?
            msg.send "this is irc adapter"
        #if robot.adapter.bot?
            #   msg.send "this is campfire ?"
    if robot.adapter.repl?
        if robot.adapter.repl.terminal?
            msg.send "this is shell adapter"

robot.coffee 中添加额外参数 ,它需要一个补丁,它在代码内部,请参阅上面的更新

到目前为止我选择嗅探

关于hubot - 如何在 hubot 脚本中获取适配器名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21746880/

相关文章:

Hubot 的 github-pull-request-notifier.coffee

Hubot 无法连接到 Rocket Chat?

coffeescript - Hubot 听觉变量

heroku - 如何在 Slack 中使用 Hubot

node.js - 如何通过 IRC 适配器使用 Hubot 和 node-cron

node.js - Hubspot 融合集成

javascript - 使用 hubot-test-helper 和 jest 测试 Hubot

javascript - 无法在 Node 应用程序中解析 json

hubot - 如何设置Hubot基本权限?

regex - 在 Coffeescript 中匹配 Hubot 的名字