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