Attachments not being sent using Web API (chat.postMessage)
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Description
Trying to send attachments using the chat.postMessage method. The example doesn't include any "optional parameters", but following the guidelines at https://slackapi.github.io/node-slack-sdk/basic_usage#general-web-api-patterns here is my code:
var attachments = [
{
"callback_id": "nlp_flag",
"actions": [
{
"name": "flag",
"text": "Flag",
"type": "button",
"value": 1
}
]
}
];
botSlack.chat.postMessage(channel, text, { attachments: attachments }, function(err, res) {
if (err) {
console.log('Error:', err);
} else {
console.log('Reply sent: ', res);
}
});
Reproducible in:
v3.9.0
Expected result:
Message to be sent with attachment
Actual result:
Message sent successfully. No error. But no attachment. The res value gets written to the console log and includes the json of the bot's message, which does not show any attachment.
Note that other "optional parameters", such as icon_url, do get sent and rendered as expected.
Through trial and error I discovered the issue was that my attachment was missing a fallback element. After adding a fallback element, it worked.
An error or warning would be helpful in such cases. FWIW, I also tried botkit, with the same results: no attachment posted without a fallback and also no error/warning.
Thanks for the feedback @markcarey. I've taken this back to the rest of the team. We're also discussing possibly just defaulting "fallback" to something like "Preview not available" or something sufficiently generic.
A side note: I haven't come up with a great way to surface warnings from the API response within the SDK overall. If you have any thoughts regarding that, I'd welcome that discussion.
Closing because I don't think there's any action necessary in the SDK at this point.
Thanks @aoberoi
+1 for the idea of defaulting fallback -- I like it.