Open minuq opened 4 years ago
Interesting. Can you deploy with SLACK_DEBUG=true
env var? The console (as in actual terminal/stdout) should dump full req/res and we’ll see what we get.
First of all there's
2020-05-12T18:24:29.995307732Z 2020-5-12 20:24:29 - [debug] slack
2020-05-12T18:24:29.998648470Z unable_to_rtm_start xoxb-789...n85
2020-05-12T18:24:29.998667590Z { Error: An API error occurred: not_allowed_token_type
2020-05-12T18:24:29.998670746Z at platformErrorFromResult (/data/node_modules/@slack/client/dist/WebClient.js:770:42)
2020-05-12T18:24:29.998673712Z at __await.makeRequest.then (/data/node_modules/@slack/client/dist/WebClient.js:484:39)
2020-05-12T18:24:29.998676337Z at process._tickCallback (internal/process/next_tick.js:68:7)
2020-05-12T18:24:29.998678783Z code: 'slackclient_platform_error',
2020-05-12T18:24:29.998681179Z data: { ok: false, error: 'not_allowed_token_type' } }
2020-05-12T18:24:30.000759817Z ---------------------------------------------------------------------
when deploying, but i guess that's due to my token not supporting RTM (it's "the new kind").
2020-05-12T18:31:07.419656260Z 2020-5-12 20:31:7 - [debug] slack
2020-05-12T18:31:07.420090151Z slack-web-out incomiming message
2020-05-12T18:31:07.420105050Z { topic: 'files.upload',
2020-05-12T18:31:07.420177101Z payload:
2020-05-12T18:31:07.420181117Z { channels: 'bastelecke',
2020-05-12T18:31:07.420185898Z file: <Buffer 74 65 73 74 0a>,
2020-05-12T18:31:07.420190173Z filename: 'Original.txt',
2020-05-12T18:31:07.420194222Z thread_ts: '1589308267.042100',
2020-05-12T18:31:07.420198296Z unfurl_media: false,
2020-05-12T18:31:07.420202307Z initial_comment: 'bla',
2020-05-12T18:31:07.420206297Z title: 'Original.txt' },
2020-05-12T18:31:07.420210442Z slackState: { channels: {}, members: {}, bots: { BRPBBT4Q2: [Object] } },
2020-05-12T18:31:07.420465255Z parts:
2020-05-12T18:31:07.420469248Z { id: '687fc95a.c5c558',
2020-05-12T18:31:07.420473274Z type: 'array',
2020-05-12T18:31:07.420477250Z count: 1,
2020-05-12T18:31:07.420481269Z len: 1,
2020-05-12T18:31:07.420485288Z index: 0 },
2020-05-12T18:31:07.420489345Z _msgid: 'f4f8701e.8dc33' }
2020-05-12T18:31:07.423740304Z [WARN] @slack/client:WebClient:0 http request failed The first argument must be one of type string or Buffer. Received type boolean
2020-05-12T18:31:07.423781038Z ---------------------------------------------------------------------
2020-05-12T18:31:07.423788235Z ---------------------------------------------------------------------
2020-05-12T18:31:07.423792836Z 2020-5-12 20:31:7 - [debug] slack
2020-05-12T18:31:07.423797147Z slack-web-out call
2020-05-12T18:31:07.423801318Z files.upload { channels: 'bastelecke',
2020-05-12T18:31:07.423805545Z file: <Buffer 74 65 73 74 0a>,
2020-05-12T18:31:07.423810136Z filename: 'Original.txt',
2020-05-12T18:31:07.423814258Z thread_ts: '1589308267.042100',
2020-05-12T18:31:07.423818380Z unfurl_media: false,
2020-05-12T18:31:07.423822578Z initial_comment: 'bla',
2020-05-12T18:31:07.423826702Z title: 'Original.txt' }
2020-05-12T18:31:07.423830774Z ---------------------------------------------------------------------
2020-05-12T18:31:07.423834967Z ---------------------------------------------------------------------
2020-05-12T18:31:07.423839189Z 2020-5-12 20:31:7 - [debug] slack
2020-05-12T18:31:07.423843288Z slack-web-out error response
2020-05-12T18:31:07.423847372Z undefined
2020-05-12T18:31:07.423851503Z ---------------------------------------------------------------------
The files appear on my thread after a slight delay, at first i thought about it being a timing issue ("node awaiting an immediate response while the slack api is still processing the request" sort of issue)
Ok for some reason it’s throwing an error.
If you’re able to tweak the running code at all in your environment then remove .data
from here: https://github.com/yayadrian/node-red-slack/blob/9136f5f9a6489f1be4268a9d285ca026ffa690e2/slackpost.js#L1311
If not I’ll fire it up and see if I get a failure in my setup or not.
I changed line 1311 to what you proposed, output looks pretty much the same to me
2020-05-13T08:07:53.690825148Z slack-web-out incoming message
2020-05-13T08:07:53.690843868Z { topic: 'files.upload',
2020-05-13T08:07:53.690966479Z payload:
2020-05-13T08:07:53.690971566Z { channels: 'bastelecke',
2020-05-13T08:07:53.690976720Z file: <Buffer 74 65 73 74 0a>,
2020-05-13T08:07:53.690982210Z filename: 'Original.txt',
2020-05-13T08:07:53.690987389Z thread_ts: '1589357273.000800',
2020-05-13T08:07:53.690992601Z unfurl_media: false,
2020-05-13T08:07:53.690997690Z initial_comment: 'bla',
2020-05-13T08:07:53.691002837Z title: 'Original.txt' },
2020-05-13T08:07:53.691008141Z slackState: { channels: {}, members: {}, bots: { BRPBBT4Q2: [Object] } },
2020-05-13T08:07:53.691370137Z parts:
2020-05-13T08:07:53.691375352Z { id: '9ecd2e98.91e36', type: 'array', count: 1, len: 1, index: 0 },
2020-05-13T08:07:53.691380802Z _msgid: 'f0022556.206948' }
2020-05-13T08:07:53.691403071Z ---------------------------------------------------------------------
2020-05-13T08:07:53.691409879Z ---------------------------------------------------------------------
2020-05-13T08:07:53.691415288Z 2020-5-13 10:7:53 - [debug] slack
2020-05-13T08:07:53.691430902Z slack-web-out call
2020-05-13T08:07:53.691436289Z files.upload { channels: 'bastelecke',
2020-05-13T08:07:53.691441569Z file: <Buffer 74 65 73 74 0a>,
2020-05-13T08:07:53.691447054Z filename: 'Original.txt',
2020-05-13T08:07:53.691452296Z thread_ts: '1589357273.000800',
2020-05-13T08:07:53.691457495Z unfurl_media: false,
2020-05-13T08:07:53.691462644Z initial_comment: 'bla',
2020-05-13T08:07:53.691467806Z title: 'Original.txt' }
2020-05-13T08:07:53.691473066Z ---------------------------------------------------------------------
2020-05-13T08:07:53.696190353Z [WARN] @slack/client:WebClient:0 http request failed The first argument must be one of type string or Buffer. Received type boolean
2020-05-13T08:07:53.696340620Z ---------------------------------------------------------------------
2020-05-13T08:07:53.696348905Z 2020-5-13 10:7:53 - [debug] slack
2020-05-13T08:07:53.696351768Z slack-web-out error response
2020-05-13T08:07:53.696354642Z ---------------------------------------------------------------------```
After some digging in the @slack/client files and forcing the body
argument to string that files.upload does not accept POST data in json format and requires an URL encoded body.
Note that i'm way out of my comfortzone here: https://github.com/yayadrian/node-red-slack/blob/9136f5f9a6489f1be4268a9d285ca026ffa690e2/slackpost.js#L1289-L1296
Adding
case "files.upload":
let urlParameters = Object.entries(options)
.map((e) => e.join("="))
.join("&");
options.text = urlParameters;
break;
to the switch() resulted in instant uploads of files, opposed to the 30s-2min delay that usually happens and a valid response from slack. This however only works for raw text and i've got no clue how to send multipart data :)
msg.topic = "files.upload"
msg.payload = {
channels: "foo",
content: "bar",
filename: "filename",
}
return msg
Yeah I assumed it had something to do with the special content type handling etc. I’ll do some digging on this and see if we can’t create something that’s nice and easy to use. Thanks!
How to reproduce: Create a msg object and pipe it into the slack-web-out node:
Files get uploaded to my slack channel fine, however according to the documentation a file object should be returned which according to slack-web-out node info should be in msg.payload.
slack-web-out returns a slackState, but no payload