@@ -1,6 +1,6 @@ |
||
1 | 1 |
{ |
2 | 2 |
"name": "hubot-multi-adapter", |
3 |
- "version": "0.2.7", |
|
3 |
+ "version": "0.3.1", |
|
4 | 4 |
"description": "A Hubot adapter that can receive messages thru socket.io or telegram", |
5 | 5 |
"main": "src/multi-adapter", |
6 | 6 |
"scripts": { |
@@ -27,4 +27,18 @@ curl -XPOST https://api.telegram.org/botXXXX/deleteWebhook |
||
27 | 27 |
curl -XPOST https://api.telegram.org/botXXXX/setWebhook?url=https://example.com/api/telegram |
28 | 28 |
``` |
29 | 29 |
|
30 |
+### Webhooks |
|
31 |
+ |
|
32 |
+You can send **webhooks** thru this adapter using the endpoint ```/webhook```. Make sure your request has a body with the user object: |
|
33 |
+ |
|
34 |
+``` |
|
35 |
+"user" : { |
|
36 |
+ "first_name" : "John", |
|
37 |
+ "last_name" : "Doe", |
|
38 |
+ "room" : 455098, |
|
39 |
+ "service" : "webhook", |
|
40 |
+ "command" : "example-command" |
|
41 |
+} |
|
42 |
+``` |
|
43 |
+ |
|
30 | 44 |
More info on *Telegram Bots* can be found [**here**](https://core.telegram.org/bots). |
@@ -64,6 +64,7 @@ class MultiAdapter extends Adapter |
||
64 | 64 |
@robot.brain.remove 'log_id_' + socket.id |
65 | 65 |
delete @sockets[socket.id] |
66 | 66 |
|
67 |
+ # Telegram Webhook |
|
67 | 68 |
app.post '/telegram-api', (req, res) => |
68 | 69 |
console.log(req.body) |
69 | 70 |
chat_id = req.body['message[chat][id]'] |
@@ -82,11 +83,12 @@ class MultiAdapter extends Adapter |
||
82 | 83 |
@receive new TextMessage user, text |
83 | 84 |
res.end() |
84 | 85 |
|
86 |
+ # General Webhook |
|
85 | 87 |
app.post '/webhook', (req, res) => |
86 | 88 |
console.log(req.body) |
87 | 89 |
chat_id = req.body.user.room |
88 | 90 |
# Get username |
89 |
- user_name = req.body.user.first_name + " " + req.body.user.last_name] |
|
91 |
+ user_name = req.body.user.first_name + " " + req.body.user.last_name |
|
90 | 92 |
command = req.body.command |
91 | 93 |
@robot.brain.set 'log_id_' + chat_id, new Date().getUTCMilliseconds(); |
92 | 94 |
user = @userForId chat_id, name: user_name, room: chat_id |