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:

-F recipient=’{“id”:“USER_ID”}’
-F message=’{“attachment”:{“type”:“image”, “payload”:{}}}’
-F filedata=@/tmp/testpng.png

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:

  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'' "{{ token }}"'

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

- id: front_motion
  alias: motion at front door
  - platform: state
    entity_id: binary_sensor.front_door_motion
    from: 'off'
    to: 'on'
  - service: shell_command.take_snapshot
      url: 'http://localhost:8123{{ }}'
      filename: '/tmp/doorbell_motion.jpg'
  - service: notify.facebook
      message: Motion at front door
      target: !secret notify_phone_number
  - service: shell_command.send_image
      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.