I have issue using bot.api.chat.unfurl, according the unfurl API everything should be correct. 馃槄
Error
debug: Got response null {"ok":false,"error":"invalid_array_arg"}
Code
controller.on('link_shared', async (bot: SlackBot, message: SlackMessage) => {
bot.replyAcknowledge()
if (message.links) {
messageAttachmentFromLinks(message.links)
.then((attachments) => keyBy(attachments, 'url'))
.then((unfurls) =>
mapValues(unfurls, (attachment) => omit(attachment, 'url'))
)
.then((unfurls) => {
const response = {
channel: message.channel,
ts: message.message_ts,
unfurls,
}
console.log(response)
bot.api.chat.unfurl(response, (err, response) => {
if (err) console.log(err)
console.log(response)
})
})
.catch(console.error)
}
})
Object sent:
{ channel: 'G9MUFFN4D',
ts: '1542867288.001200',
unfurls:
{ 'https://confluence.3shape.com/x/e4vpBg':
{ fallback:
'Some page - Some workspace - Confluence',
title:
'Some page - Some workspace - Confluence',
title_link: 'https://confluence.3shape.com/x/e4vpBg' } } }
Debug output:
debug: chat.unfurl { channel: 'G9MUFFN4D',
ts: '1542867288.001200',
unfurls:
{ 'https://confluence.3shape.com/x/e4vpBg':
{ fallback:
'Some page - Some workspace - Confluence',
title:
'Some page - Some workspace - Confluence',
title_link: 'https://confluence.3shape.com/x/e4vpBg' } },
token: 'SNIP' }
I think it fails to encode the object correctly. I'll try and implement the request on my own perhaps in JSON format to see if it handles it better.
@benbrown @peterswimm
the issue lies with querystring parsing in request. We should add useQuerystring and set it to true.
From https://github.com/request/request#requestoptions-callback
useQuerystring- if true, usequerystringto stringify and parse querystrings, otherwise useqs(default:false). Set this option totrueif you need arrays to be serialized asfoo=bar&foo=bazinstead of the defaultfoo[0]=bar&foo[1]=baz.
I believe this to be common for slack web api that they do not like PHP-style array argument
https://api.slack.com/methods/chat.postMessage
It does indeed say:
The method was passed a PHP-style array argument (e.g. with a name like foo[7]). These are never valid with the Slack API.
Created #1547
Thanks for addressing this!
Most helpful comment
@benbrown @peterswimm
the issue lies with querystring parsing in request. We should add
useQuerystringand set it to true.From https://github.com/request/request#requestoptions-callback
I believe this to be common for slack web api that they do not like PHP-style array argument
https://api.slack.com/methods/chat.postMessage
It does indeed say: