maknz / slack

A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax.
BSD 2-Clause "Simplified" License
1.17k stars 204 forks source link

How to upload files #31

Closed thorakmedichi closed 8 years ago

thorakmedichi commented 8 years ago

Hey man,

So been using your Slack Package for Laravel awhile now and been loving the simplicity of it all.

I have had a new request though that I am having a hard time figuring out how to deal with. I have been asked to send some alerts as jpg images. I know the slack API has this ability ( https://api.slack.com/methods/files.upload ) but I do not see anything in your code that deals with this. Am I just blind or does it not exist?

If it does not exist can you point me in the right direction on where to add this to your codebase.

Cheers

Ryan Stephens

maknz commented 8 years ago

Hey,

This package uses Incoming Webhooks rather than the full Slack API.

You can send an image in using the image_url field of an attachment. Try:

$client->to('#operations')->attach([
    'fallback' => 'It's all broken',
    'text' => 'It's all broken',
    'pretext' => 'From user: Jim',
    'color' => 'bad',
    'image_url' => 'http://example.com/image.jpg'
])->send('New alert from the monitoring system');
event15 commented 7 years ago

But what when I try to send for example json file?

thedotedge commented 7 years ago

Do you plan to support https://api.slack.com/methods/files.upload?

Gummibeer commented 7 years ago

Like @maknz said, this isn't supported by webhooks and the real Slack API is another world. You need an App and Token for it and a lot more differences.

If you want to use the Slack API there are some packages for it: https://github.com/JulienTant/laravel-slack-api https://github.com/palanik/slack-php and I bet that there are more.