hubot-http-adapter

1.0.1 • Public • Published

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"
  })
})

Readme

Keywords

Package Sidebar

Install

npm i hubot-http-adapter

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • k33g