Sending local image via FB messenger bot Send API (filedata)

I am trying to add camera snapshot to motion detection notification sent by messenger. Unfortunately camera only serves snapshots by cgi, and moody messenger API doesn’t accept it, so I have to download snapshot file, and then send it. Trying to use this:
https://developers.facebook.com/docs/messenger-platform/send-api-reference

specifically
-F recipient=’{“id”:“USER_ID”}’
-F message=’{“attachment”:{“type”:“image”, “payload”:{}}}’
-F filedata=@/tmp/testpng.png
https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN

A little help with setting message/data/payload? Thanks.

i hacked around this with a shell_command

In configuration.yaml I added the following commands to save and send a local image with facebook messenger:

shell_command:
  take_snapshot: 'curl "{{ url }}" --output {{ filename }} --silent'
  send_image: 'curl -F ''recipient={"phone_number":"{{ target }}"}'' -F ''message={"attachment":{"type":"image", "payload":{}}}'' -F ''filedata=@{{ filename }};type=image/jpeg'' "https://graph.facebook.com/v2.6/me/messages?access_token={{ token }}"'

Then, in an automation’s action I can save and send the image.

- id: front_motion
  alias: motion at front door
  trigger:
  - platform: state
    entity_id: binary_sensor.front_door_motion
    from: 'off'
    to: 'on'
  action:
  - service: shell_command.take_snapshot
    data_template:
      url: 'http://localhost:8123{{ states.camera.front_door.attributes.entity_picture }}'
      filename: '/tmp/doorbell_motion.jpg'
  - service: notify.facebook
    data:
      message: Motion at front door
      target: !secret notify_phone_number
  - service: shell_command.send_image
    data:
      filename: '/tmp/doorbell_motion.jpg'
      target: !secret notify_phone_number
      token: !secret facebook_token
1 Like

Did you get your Facebook curl commands to work again?

nope, something seems to be messed up with the configuration of my facebook app/page, so i just switched to pushbullet. i’m not super thrilled about having another app on my phone, but it works well.