How to have a facebook messenger bot send you a youtube video embedded in messenger
Asked Answered
M

4

12

I was wondering if it is possible to have a messenger bot send you a youtube video link and generate a playable video inside messenger the same way you can if you paste a link inside the messenger. Right now my bot can send a message with a youtube link but it just sends it as text it doesn't generate a video recognizing the title, description etc. Any help would be appreciated.

Miliary answered 3/7, 2016 at 20:49 Comment(1)
i guess this would need to be able to "parse" youtube link like the bot is sending which it does automatically with users :( there is no way to do that nowAnandrous
K
10

You can also send by OpenGraph. It will automatically display the video inside m.me chat window but in mobile iOS app, currently it redirects to youtube page:

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "attachment":{
      "type":"template",
      "payload":{
        "template_type":"open_graph",
        "elements":[
           {
            "url":"https://www.youtube.com/watch?v=y9A1MEbgLyA"    
          }
        ]
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=$TOKEN"
Kaenel answered 4/6, 2017 at 2:46 Comment(3)
developers.facebook.com/docs/messenger-platform/… This is the correct answer.Avan
How to use this inside Dialogflow?Morra
Open Graph Template is deprecated since V4.0 (2019) How we can do this now?Trejo
O
8

As of 7/1/2016, the new API docs allow video messages assuming you've got the url of the actual mp4 file. For a youtube video, that url is (purposefully) not easy to get to. There are some tools, like youtube-dl, that will get the url of a file from YouTube and it would be possible to use that url with a facebook video message. This setup is of course assuming facebook does not have any blocking in place for youtube video links.

Another approach would be to build your own combo thumbnail/video link message using a "generic template" facebook message.

Ofilia answered 9/7, 2016 at 21:34 Comment(3)
Combo approach seems good since it is easy to get the thumbnails (See #2068844), then simply have Play button that links out to the videoStripper
You can also use something like this (github.com/halgatewood/youtube-thumbnail-enhancer) to add a play icon on top of the video thumbnailStripper
Calling a YouTube video through the direct mp4 link is very slow. Could it be that Facebook is downloading that video completely before it plays it?Orifice
P
2

You can send Video with size <= 30MB with following code.

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "attachment":{
      "type":"video",
      "payload":{
        "url":"direct_url_to_video",
        "is_reusable":true
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=ACCESS_TOKEN"

After that, above command will return "attachment_id" of video From now, you can send video with attachment_id and never expire.

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "attachment":{
      "type":"video",
      "payload":{
       "attachment_id": "<attachment_id_here"
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=ACCESS_TOKEN"
Pinochle answered 25/10, 2017 at 7:54 Comment(0)
B
0

I found a temporary solution (videos may expire). Try this site: http://catchvideo.net/. It will give you the playable video link you can use your bot to send in the messenger as an attachment. Hope this helps!

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "attachment":{
      "type":"video",
      "payload":{
        "url":"THE_LINK_FROM_WEBSITE_ABOVE" (example: https://redirector.googlevideo.com/videoplayback?itag=18.....)
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=ACCESS_TOKEN"
Beethoven answered 17/6, 2017 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.