Botkit: chat unfurl invalid array argument

Created on 22 Nov 2018  路  4Comments  路  Source: howdyai/botkit

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' }
Slack-related help wanted

Most helpful comment

@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, use querystring to stringify and parse querystrings, otherwise use qs (default: false). Set this option to true if you need arrays to be serialized as foo=bar&foo=baz instead of the default foo[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.

All 4 comments

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, use querystring to stringify and parse querystrings, otherwise use qs (default: false). Set this option to true if you need arrays to be serialized as foo=bar&foo=baz instead of the default foo[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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dfischer picture dfischer  路  4Comments

benbrown picture benbrown  路  3Comments

fieldcorbett picture fieldcorbett  路  4Comments

abinashmohanty picture abinashmohanty  路  4Comments

abinashmohanty picture abinashmohanty  路  4Comments