Auteur | SHA1 | Message | Date |
---|---|---|---|
James Peret | 0436f5315a | 7 ans auparavant | |
James Peret | 6d5bb9e2ba | 7 ans auparavant |
@@ -1,6 +1,6 @@ |
||
1 | 1 |
{ |
2 | 2 |
"name": "hubot-multi-adapter", |
3 |
- "version": "0.3.6", |
|
3 |
+ "version": "0.3.7", |
|
4 | 4 |
"description": "A Hubot adapter that can receive messages thru socket.io or telegram", |
5 | 5 |
"main": "src/multi-adapter", |
6 | 6 |
"scripts": { |
@@ -4,9 +4,9 @@ catch |
||
4 | 4 |
prequire = require('parent-require') |
5 | 5 |
{Robot,Adapter,TextMessage,User} = prequire 'hubot' |
6 | 6 |
|
7 |
-port = parseInt process.env.HUBOT_SOCKETIO_PORT or 9090 |
|
8 |
-io = require('socket.io').listen port |
|
9 |
-console.log("socket.io server on port " + port); |
|
7 |
+socket_port = parseInt process.env.HUBOT_SOCKETIO_PORT or 9090 |
|
8 |
+io = require('socket.io').listen socket_port |
|
9 |
+console.log("socket.io server on port " + socket_port); |
|
10 | 10 |
|
11 | 11 |
express = require('express') |
12 | 12 |
app = express() |
@@ -14,8 +14,9 @@ bodyParser = require("body-parser") |
||
14 | 14 |
app.use(bodyParser.urlencoded({ extended: false })) |
15 | 15 |
app.use(bodyParser.json()); |
16 | 16 |
|
17 |
-app.listen 80, => |
|
18 |
- console.log('HTTP server on port 80') |
|
17 |
+http_port = parseInt process.env.HUBOT_HTTP_PORT or 80 |
|
18 |
+app.listen http_port, => |
|
19 |
+ console.log('HTTP server on port ' + http_port) |
|
19 | 20 |
|
20 | 21 |
TelegramBot = require('node-telegram-bot-api') |
21 | 22 |
#Telegram bot token (given when you create a new bot using the BotFather); |
@@ -67,18 +68,19 @@ class MultiAdapter extends Adapter |
||
67 | 68 |
# Telegram Webhook |
68 | 69 |
app.post '/telegram-api', (req, res) => |
69 | 70 |
console.log(req.body) |
70 |
- chat_id = req.body['message[chat][id]'] |
|
71 |
+ console.log(req.body.message.text) |
|
72 |
+ chat_id = req.body.message.chat.id |
|
71 | 73 |
# Get username |
72 |
- user_name = req.body['message[from][first_name]'] + " " + req.body['message[from][last_name]'] |
|
73 |
- text = req.body['message[text]'] |
|
74 |
+ user_name = req.body.message.from.first_name + " " + req.body.message.from.last_name |
|
75 |
+ text = req.body.message.text |
|
74 | 76 |
@robot.brain.set 'log_id_' + chat_id, new Date().getUTCMilliseconds(); |
75 | 77 |
user = @userForId chat_id, name: user_name, room: chat_id |
76 | 78 |
console.log("Message Received from user " + user_name + ":" ) |
77 | 79 |
console.log(text) |
78 | 80 |
user.service = "telegram" |
79 |
- user.first_name = req.body['message[from][first_name]'] |
|
80 |
- user.last_name = req.body['message[from][last_name]'] |
|
81 |
- user.username = req.body['message[from][username]'] |
|
81 |
+ user.first_name = req.body.message.from.first_name |
|
82 |
+ user.last_name = req.body.message.from.last_name |
|
83 |
+ user.username = req.body.message.from.username |
|
82 | 84 |
user.room = chat_id |
83 | 85 |
user.msg_type = "message" |
84 | 86 |
@receive new TextMessage user, text |