Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for upload of remote or local files to slack #8278

Merged
merged 2 commits into from Jul 7, 2017

Conversation

simaosimao
Copy link
Contributor

@simaosimao simaosimao commented Jul 1, 2017

Description:

The notify.slack platform currently supports sending text messages and structured message attachments (see chat.postMessage). This PR's intention is to add support for uploading files either from the local machine/server or from a remote url (See files.upload).

I am using this feature to post security camera still pictures to a slack channel when certain events occur. Might be useful to others...?

Example: Post file or image by url

Use the following service data for notify.slack in order to directly post a remote file:

{
  "message":"Message that will be added as a comment to the file, e.g. photo.",
  "title":"Title of the file, e.g. photo",
  "data":{
    "file":{
      "url":"http://<url to file, photo, security camera etc>",
      "username":"optional user, if necessary",
      "password":"optional password, if necessary",
      "auth":"digest"
    }
  }
}

"auth":"digest" is optional, too. If omitted basic authentication is used.

Example: Post file or image by local path

Use the following service data for notify.slack in order to post local file

{
  "message":"Message that will be added as a comment to the file, e.g. photo.",
  "title":"Title of the file, e.g. photo",
  "data":{
    "file":{
      "path":"/path/to/file.ext"
    }
  }
}

Sidenote

This is my first PR (at all) and I am no python developer. I tried to familiarize with applying rules and conventions, running tests etc. Still I might have missed something ... please excuse any mistakes.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2949

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

@mention-bot
Copy link

@simaosimao, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fabaff, @Khabi and @balloob to be potential reviewers.

@homeassistant
Copy link
Contributor

Hi @simaosimao,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Copy link
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should make a helper function for fileload


elif local_path is not None:
# load file from local path on server
return open(local_path, "rb")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need check the path with hass.config.is_allowed_path

@simaosimao
Copy link
Contributor Author

Hi @pvizeli, thanks for your feedback! Using suggested check now. Had to move the load_file method into the SlackNotificationService class in order to keep a reference to is_allowed_path.

Also had a look at the telegram bot which has a similar method to load a file. We might extract those to a helper function as you mentioned above in a follow up issue 😉

Opened #8291, as is_allowed_path could be further secured.

@balloob
Copy link
Member

balloob commented Jul 7, 2017

Awesome 🎉 🌮 🐬

@balloob balloob merged commit fb184b4 into home-assistant:dev Jul 7, 2017
@simaosimao
Copy link
Contributor Author

Thx 😄

@simaosimao simaosimao deleted the slack-remote-files branch July 7, 2017 07:48
@balloob balloob mentioned this pull request Jul 13, 2017
dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
…stant#8278)

* Added support for upload of remote or local files to slack

* Checking local file with hass.config.is_allowed_path prior to posting it
@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants