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

Implement Twilio SMS notify MediaUrl support #24971

Merged

Conversation

Chris-Johnston
Copy link
Contributor

@Chris-Johnston Chris-Johnston commented Jul 5, 2019

Description:

Adds support for setting the media_url parameter of the twilio API client with an optional attribute under the notify service data attribute.

Per the twilio docs this feature is only available in the US and Canada, for GIF, PNG, or JPEG content.

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#9792

Example entry for configuration.yaml (if applicable):

action:
  - data:
    message: Motion detected.
    data:
      - media_url: http://path.to.your.image/here.jpg

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

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

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

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

Adds support for setting the `media_url` parameter of the twilio API
client with an optional attribute under the notify `data`
attribute.

Per the twilio docs (https://www.twilio.com/docs/sms/send-messages#include-medi$
this feature is only available in the US and Canada, for
GIF, PNG, or JPEG content.
@homeassistant
Copy link
Contributor

Hi @Chris-Johnston,

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!

@ghost
Copy link

ghost commented Jul 5, 2019

Hey there @robbiet480, mind taking a look at this pull request as its been labeled with a integration (twilio_sms) you are listed as a codeowner for? Thanks!

This is a automatic comment generated by codeowners-mention to help ensure issues and pull requests are seen by the right people.

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.

Use follow style instead object():

twillo_args = {
    'message': message,
    'from_number': self.from_... 
}

if ATTR_MEDIAURL in data:
   twillo_args['media_url'] = data[...]

...

self.client.messages.create(to=target, **twillo_args)

after testing locally, seems like the previous way of using
object() was not working. this seems to be working
@Chris-Johnston
Copy link
Contributor Author

Chris-Johnston commented Jul 7, 2019

Seems to be working on my machine. Once I got a local test environment set up, the object() method was not working, but kwargs seems to be working.

Message w/o image:

{
"message": "test",
"target": [ "+1xxxxxxxxxx" ]
}
2019-07-07 15:13:35 INFO (SyncWorker_8) [twilio.http_client] POST Request: https://api.twilio.com/2010-04-01/Accounts/xxxxx/Messages.json
2019-07-07 15:13:35 INFO (SyncWorker_8) [twilio.http_client] PAYLOAD: {'To': '+1xxxxxxxxxx', 'From': '1xxxxxxxxxx', 'Body': 'test'}
2019-07-07 15:13:35 INFO (SyncWorker_8) [twilio.http_client] POST Response: 201 {"sid": "xxxxx", "date_created": "Sun, 07 Jul 2019 22:13:35 +0000", "date_updated": "Sun, 07 Jul 2019 22:13:35 +0000", "date_sent": null, "account_sid": "xxxxx", "to": "+1xxxxxxxxxx", "from": "+1xxxxxxxxxx", "messaging_service_sid": null, "body": "Sent from your Twilio trial account - test", "status": "queued", "num_segments": "1", "num_media": "0", "direction": "outbound-api", "api_version": "2010-04-01", "price": null, "price_unit": "USD", "error_code": null, "error_message": null, "uri": "/2010-04-01/Accounts/xxxxx/Messages/xxxx.json", "subresource_uris": {"media": "/2010-04-01/Accounts/xxx/Messages/xxx/Media.json"}}

Message w/ image:

{
"message": "test",
"target": [ "+1xxxxxxxxxx" ],
"data" : { "media_url" : "https://blog.codinghorror.com/content/images/uploads/2007/03/6a0120a85dcdae970b0128776ff992970c-pi.png" }
}
2019-07-07 15:14:26 INFO (SyncWorker_3) [twilio.http_client] POST Request: https://api.twilio.com/2010-04-01/Accounts/xxx/Messages.json
2019-07-07 15:14:26 INFO (SyncWorker_3) [twilio.http_client] PAYLOAD: {'To': '+1xxxxxxxxxx', 'From': '1xxxxxxxxxx', 'Body': 'test aaaaaa', 'MediaUrl': 'https://url.goes.here/test.png'}
2019-07-07 15:14:27 INFO (SyncWorker_3) [twilio.http_client] POST Response: 201 {"sid": "xxx", "date_created": "Sun, 07 Jul 2019 22:14:27 +0000", "date_updated": "Sun, 07 Jul 2019 22:14:27 +0000", "date_sent": null, "account_sid": "xxx", "to": "+1xxxxxxxxxx", "from": "+1xxxxxxxxxx", "messaging_service_sid": null, "body": "test aaaaaa", "status": "queued", "num_segments": "1", "num_media": "1", "direction": "outbound-api", "api_version": "2010-04-01", "price": null, "price_unit": "USD", "error_code": null, "error_message": null, "uri": "/2010-04-01/Accounts/xxx/Messages/xxx.json", "subresource_uris": {"media": "/2010-04-01/Accounts/xxx/Messages/xxx/Media.json"}}

@pvizeli pvizeli merged commit 32685f1 into home-assistant:dev Jul 8, 2019
@Chris-Johnston Chris-Johnston deleted the feature/twilio-sms-images branch July 8, 2019 13:55
KJonline pushed a commit to Rendili/home-assistant that referenced this pull request Jul 8, 2019
… into hive_water_heater

* 'hive_water_heater' of github.com:Rendili/home-assistant: (21 commits)
  Sensibo, add HVAC_MODE_OFF (home-assistant#25016)
  Add support for arcam fmj receivers (home-assistant#24621)
  Enphase envoy individual inverter production (home-assistant#24445)
  Implement Twilio SMS notify MediaUrl support (home-assistant#24971)
  Climate 1.0 (home-assistant#23899)
  Correct socket use in cert_expiry platform (home-assistant#25011)
  Added missing yeelight models mapping (home-assistant#24963)
  Install requirements for integrations in packages before importing them. (home-assistant#25005)
  Upgrade insteonplm to 0.16.0 and add INSTEON scene triggering (home-assistant#24765)
  Upgrade hdate==0.8.8 (home-assistant#25008)
  upgrade switchmate to latest lib (home-assistant#25006)
  Test dependency updates (home-assistant#25004)
  Add support for aurora ABB Powerone solar photovoltaic inverter (home-assistant#24809)
  Sleepiq single sleeper crash (home-assistant#24941)
  Changes as per code review of home-assistant#24646 (home-assistant#24917)
  Upgrade mypy to 0.711, drop no longer needed workarounds (home-assistant#24998)
  Adds Stale Probot for issues (home-assistant#24985)
  Adds Lock Threads Probot (home-assistant#24984)
  Switched from tuyapy to tuyaha as 1st one is not maintained (home-assistant#24821)
  Fix errors if rest source becomes unavailable (home-assistant#24986)
  ...

# Conflicts:
#	homeassistant/components/hive/__init__.py
#	homeassistant/components/hive/climate.py
@lock lock bot locked and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants