Question

Hubot can support different adapter like Shell/IRC/XMPP.

If the adapter is set in environment variable HUBOT_ADAPTER, then process.env.HUBOT_ADAPTER can be checked.

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

But it also support to use options --adapter, and how can I detect this in the hubot script.

I want to write different logic based on adapter like chat-room, userid.

Otherwise I need to prepare separate scripts for different adapater.

Was it helpful?

Solution

Got the two suggestions from github issues https://github.com/github/hubot/issues/647

[update] this issue is fixed in source code robot.coffee by adding adapterName, so you can check robot.adapterName since version 2.7.2, see changes

sniff, It could be checked with special information in adapter, and possible checks below for my environment on 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"

add extra parameter in robot.coffee, it needs a patch for this, it is inside code see update above

I choose sniff so far

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top