0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.