Skip to content

bots-squad/hubot-http-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hubot http adapter

An adapter (not a plugin) for Hubot to work via HTTP using Json as data format.

Useful for headless chat.

inspiration: https://github.com/wichon/hubot-json-rest

Setup

Set environment variable:

  • HUBOT_POST_RESPONSES_URL this is the url to send (POST method) Hubot responses.

you need a webapp "listening" on this url, eg:

// This is an Express application
app.post(`${process.env.HUBOT_POST_RESPONSES_URL}/:room`, (req, res) => {
  console.log(req.body, req.params);
  res.status(201).end();
});

Hubot response is sent in json format, with the following structure:

{
  from: 'bot name',
  message: 'Hello 🌍'
}

Send message to Hubot

Typically messages to Hubot have three parameters: Message, User and Room:

// post: /receive/:room
{
  from: 'user name',
  message: 'Hello 🤖'
}

You can use fetch (https://www.npmjs.com/package/node-fetch):

// POST message to the `general` room
fetch(`${hubot_protocol}://${hubot_server_name}:${hubot_port}/receive/general`, {
  method: 'POST',
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    from: "@k33g_org",
    message: "bob help me with java"
  })
})

About

Hubot adapter using HTTP and Json as data format Edit

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published