I'm using the Slack Poster gem to send messages to a Slack channel via a webhook.
I can send a message like so, and it comes through fine:
string = "Here is your attachment"
poster = Slack::Poster.new(SLACK_WEBHOOK_URL)
message = Slack::Message.new(string)
poster.send_message(message)
Next I want to attach a JSON file to the message. I can make an attachment object, and add it to the message, but I can't see how to add the actual file into the attachment object.
filename = "/path/to/my/file.json"
attachment = Slack::Attachment.new
#how do i give it the actual file?
message.attachments << attachment
poster.send_message(message)
I tried doing this:
attachment.add_field("error_log", File.read(filename))
but that shows the content of the file in the actual message, rather than it being a downloadable file.