Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

chat unfurl invalid array argument #1522

Closed
jetersen opened this issue Nov 22, 2018 · 4 comments · Fixed by #1547
Closed

chat unfurl invalid array argument #1522

jetersen opened this issue Nov 22, 2018 · 4 comments · Fixed by #1547

Comments

@jetersen
Copy link
Contributor

jetersen commented Nov 22, 2018

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' }
@jetersen
Copy link
Contributor Author

jetersen commented Dec 3, 2018

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.

@jetersen
Copy link
Contributor Author

jetersen commented Dec 18, 2018

@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.

@jetersen
Copy link
Contributor Author

Created #1547

@benbrown
Copy link
Contributor

Thanks for addressing this!

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

Successfully merging a pull request may close this issue.

3 participants