Slackbot附件 - 这有什么问题吗?

Rah*_*ani 5 slack-api

我正在使用howkit来为postMessage方法调用api.invalid_array_arg当我传递附件属性时,它给我错误.它获得POST的方式有问题

bot.api.chat.postMessage(
        {
            channel : '#general',
            text    : 'hi',
            parse   : true,
            username: '@' + bot.identity.name,
            as_user : true,
            icon_url: listOfMessages.logoUrl,
            attachments: [{"pretext": "pre-hello", "text": "text-world"}]

        }, function (err,res) {
            if(err) console.log(err);
            console.log(res);
        }
    );
Run Code Online (Sandbox Code Playgroud)

Tim*_*m B 16

我遇到了同样的问题并通过对数组进行字符串化来修复它.

attachments: JSON.stringify([{"pretext": "pre-hello", "text": "text-world"}])
Run Code Online (Sandbox Code Playgroud)

  • 在ruby slack-api gem中有同样的问题.重要的是将整个附件数组转换为json,而不仅仅是附件中的对象,例如:`attachments:[attachment] .to_json` (3认同)