Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source_channel need to be string and not integer #145

Open
alisson276 opened this issue Nov 6, 2017 · 4 comments
Open

source_channel need to be string and not integer #145

alisson276 opened this issue Nov 6, 2017 · 4 comments

Comments

@alisson276
Copy link

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
         }
       });
@alisson276
Copy link
Author

Anyone?

@arm4b
Copy link
Member

arm4b commented May 3, 2018

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.

@surfer190
Copy link

I can confirm that this works!

@surfer190
Copy link

surfer190 commented May 22, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants