Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slackbot Attachment - Is something wrong with this?

Tags:

slack-api

I am using botkit by howdy to make the api call for postMessage method. Its giving me invalid_array_arg error when I am passing attachment property. Is something wrong with the way its getting POSTed

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);
        }
    );
like image 306
Rahul Dhawani Avatar asked Mar 02 '16 18:03

Rahul Dhawani


1 Answers

I was running into this same issue and fixed it by stringifying the array.

attachments: JSON.stringify([{"pretext": "pre-hello", "text": "text-world"}])
like image 76
Tim B Avatar answered Sep 24 '22 22:09

Tim B