hubot-stackstorm
hubot-stackstorm copied to clipboard
source_channel need to be string and not integer
If the source_channel is not a String, like Telegram, the POST in /api/v1/aliasexecution fail with message:
Nov 6 17:14:40 stackstorm hubot: [Mon Nov 06 2017 17:14:40 GMT-0200 (-02)] DEBUG Sending command payload: {"name":"remote_shell_cmd","format":"(run|execute) {{cmd}} on {{hosts}}","command":"execute date on localhost","user":"test","source_channel":123456,"notification_route":"hubot"}
Nov 6 17:14:40 stackstorm gunicorn: 2017-11-06 17:14:40,374 INFO [-] c278448b-9896-43ed-b0e4-b298d60f9897 - 400 58 181.033ms (content_length=58,request_id='c278448b-9896-43ed-b0e4-b298d60f9897',runtime=181.033,remote_addr='127.0.0.1',status=400,method='POST',path='/v1/aliasexecution')
Nov 6 17:14:40 stackstorm hubot: [Mon Nov 06 2017 17:14:40 GMT-0200 (-02)] ERROR Failed to create an alias execution: { name: 'APIError',
Nov 6 17:14:40 stackstorm hubot: status: 400,
Nov 6 17:14:40 stackstorm hubot: message: '123456 is not of type \'string\'' }
My workarround is edit the file scripts/stackstorm.js and set:
--- chatops/node_modules/hubot-stackstorm/scripts/stackstorm.js 2017-11-06 17:13:59.878000000 -0200
+++ chatops/node_modules/hubot-stackstorm/scripts/stackstorm.edit.js 2017-11-06 17:18:03.657000000 -0200
@@ -266,7 +266,7 @@
postDataHandler.postData({
whisper: false,
user: addressee.name,
- channel: addressee.room,
+ channel: String(addressee.room),
message: message,
extra: {
color: '#F35A00'
@@ -283,7 +283,7 @@
'format': format_string,
'command': command,
'user': addressee.name,
- 'source_channel': addressee.room,
+ 'source_channel': String(addressee.room),
'notification_route': env.ST2_ROUTE || 'hubot'
};
@@ -296,7 +296,7 @@
'parameters': {
'uuid': twofactor_id,
'user': addressee.name,
- 'channel': addressee.room,
+ 'channel': String(addressee.room),
'hint': action_alias.description
}
});
Anyone?
It looks like we don't support Telegram in st2chatops
yet, according to https://github.com/StackStorm/st2chatops/blob/4547240069906c1ea5411068183fa22c434559f1/package.json#L8-L23
It might work, but none tested it.
For so simple code change you might open a PR in this repo. It looks like StackStorm API is expecting a string for a channel, so type casting int to string should be safe and won't break other chat providers.
I can confirm that this works!
I've noticed an issue where special characters cause an error when interacting with telegram.
May 22 11:15:48 st2 hubot[24381]: [Wed May 22 2019 11:15:48 GMT+0000 (Coordinated Universal Time)] DEBUG Message length: 727
May 22 11:15:48 st2 hubot[24381]: [Wed May 22 2019 11:15:48 GMT+0000 (Coordinated Universal Time)] DEBUG Message parts: 1
May 22 11:15:49 st2 hubot[24381]: [Wed May 22 2019 11:15:49 GMT+0000 (Coordinated Universal Time)] ERROR Error: Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 400
May 22 11:15:49 st2 hubot[24381]: at Function.TelegramBot.error (/opt/stackstorm/chatops/node_modules/telegrambot/lib/telegrambot.js:26:15)
May 22 11:15:49 st2 hubot[24381]: at Request._callback (/opt/stackstorm/chatops/node_modules/telegrambot/lib/telegrambot.js:47:66)
May 22 11:15:49 st2 hubot[24381]: at Request.self.callback (/opt/stackstorm/chatops/node_modules/request/request.js:186:22)
May 22 11:15:49 st2 hubot[24381]: at Request.emit (events.js:189:13)
May 22 11:15:49 st2 hubot[24381]: at Request.<anonymous> (/opt/stackstorm/chatops/node_modules/request/request.js:1163:10)
May 22 11:15:49 st2 hubot[24381]: at Request.emit (events.js:189:13)
May 22 11:15:49 st2 hubot[24381]: at IncomingMessage.<anonymous> (/opt/stackstorm/chatops/node_modules/request/request.js:1085:12)
May 22 11:15:49 st2 hubot[24381]: at Object.onceWrapper (events.js:277:13)
May 22 11:15:49 st2 hubot[24381]: at IncomingMessage.emit (events.js:194:15)
May 22 11:15:49 st2 hubot[24381]: at endReadableNT (_stream_readable.js:1125:12)
May 22 11:15:49 st2 hubot[24381]: at process._tickCallback (internal/process/next_tick.js:63:19)
I think if we can fix this it will go a long way towards telegram support
Update:
The problem seems to be coming from the hubot-telegram
package