Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Created February 17, 2012 06:36
Show Gist options
  • Save mikebridge/1851316 to your computer and use it in GitHub Desktop.
Save mikebridge/1851316 to your computer and use it in GitHub Desktop.
Adapter from hubot to an A.L.I.C.E pandorabot
# Chat with hubie.
#
# hubie <anything>
#
# don't forget to set HUBOT_PANDORA_BOTID = <botid>
QS = require "querystring"
module.exports = (robot) ->
robot.hear /hubie[,\s]+(.*)/i, (msg) ->
user = msg.message.user.name
query = msg.match[1]
if query
botid = process.env.HUBOT_PANDORA_BOTID
if !botid
msg.send "Please set the HUBOT_PANDORA_BOTID"
return
data = QS.stringify botid: botid, custid: user, input: query
msg.http('http://www.pandorabots.com')
.path("/pandora/talk-xml")
.header("Content-Type", "application/x-www-form-urlencoded")
.post(data) (err, resp, body) ->
Parser = require("xml2js").Parser
(new Parser).parseString body, (err, json)->
if (!json)
msg.send "Uh, oh, my brain is not connected. :("
return
msg.send(json.that)
@njia
Copy link

njia commented Oct 21, 2014

Hi Mike

How can I get a PANDORA_BOTID? I tried their website and send a request but only got a response asking me to try playground first and does not look like what you used in this gist.

@EthGambler
Copy link

Found bot id in the website url but it's still not working for me

http://demo.vhost.pandorabots.com/pandora/talk?botid=b0dafd24ee35a477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment