pimax / fb-messenger-php

Facebook Messenger Bot PHP API
GNU General Public License v2.0
314 stars 147 forks source link

VideoMessage #169

Open Yggdrasills opened 5 years ago

Yggdrasills commented 5 years ago

I'm sorry, it is my first issue on GitHub. I can't send video to the chat from my profile or youtube. Can you help me?

Here is my code:

$bot->send(new VideoMessage($message['sender']['id'], "https://youtu.be/_PBlykN4KIY"));

But it works with photos

$bot->send(new ImageMessage($message['sender']['id'], "imagepath"));

o2-web commented 5 years ago

@Yggdrasills you need to provide a link to the video file, not to the page

to get a link to a video file from youtube, I use this api https://api.unblockvideos.com/youtube_downloader?id=_PBlykN4KIY&selector=mp4

Yggdrasills commented 5 years ago

@Yggdrasills you need to provide a link to the video file, not to the page

to get a link to a video file, I use this api https://api.unblockvideos.com/youtube_downloader?id=_PBlykN4KIY&selector=mp4

I tried to use this link, but it doesn't work https://www.facebook.com/100035197906425/videos/116234242893172/.mp4

o2-web commented 5 years ago

https://www.facebook.com/100035197906425/videos/116234242893172/.mp4 this is also a link to an html page, not a video file

Yggdrasills commented 5 years ago

https://www.facebook.com/100035197906425/videos/116234242893172/.mp4 this is also a link to an html page, not a video file

Should this work? $bot->send(new VideoMessage($message['sender']['id'], "https://api.unblockvideos.com/youtube_downloader?id=_PBlykN4KIY&selector=mp4"));

I tried it, but it did not work

o2-web commented 5 years ago

https://www.facebook.com/100035197906425/videos/116234242893172/.mp4 this is also a link to an html page, not a video file

Should this work? $bot->send(new VideoMessage($message['sender']['id'], "https://api.unblockvideos.com/youtube_downloader?id=_PBlykN4KIY&selector=mp4"));

I tried it, but it did not work

this should not work, this is an api for getting a link to a file by ID video from YouTube

Yggdrasills commented 5 years ago

https://www.facebook.com/100035197906425/videos/116234242893172/.mp4 this is also a link to an html page, not a video file

Should this work? $bot->send(new VideoMessage($message['sender']['id'], "https://api.unblockvideos.com/youtube_downloader?id=_PBlykN4KIY&selector=mp4")); I tried it, but it did not work

this should not work, this is an api for getting a link to a file by ID video from YouTube

Thanks, it helped. However, when the video is sent, the bot starts spamming without stopping

$bot->send(new VideoMessage($message['sender']['id'], "correct link"));

How to fix it?

After removing the video sending line, the bot still continues spamming until I restart the server

wittfabian commented 5 years ago

What do you mean with "starts spamming"? What type of messages?

Please provide examples!

jason-engage commented 5 years ago

You're probably responding to the ECHO message (which is then creating a loop). Gotta filter that out!

Yggdrasills commented 5 years ago

What do you mean with "starts spamming"? What type of messages?

Please provide examples!

https://prntscr.com/nawlhu https://prntscr.com/nawlkd https://prntscr.com/nawm7a

wittfabian commented 5 years ago

Check: https://github.com/pimax/fb-messenger-php-example/blob/master/index.php#L68

Yggdrasills commented 5 years ago

Check: https://github.com/pimax/fb-messenger-php-example/blob/master/index.php#L68

Did not help. Can I somehow send the video from my account by id? https://prntscr.com/nawvfe switch ($command) { case 'video': $bot->send(new VideoMessage($message['sender']['id'], "https://scontent-arn2-2.xx.fbcdn.net/v/t39.24130-6/57065986_419305962231452_3763318846007767803_n.mp4?_nc_cat=103&efg=eyJxZV9ncm91cHMiOlsidW5tdXRlZCJdLCJ2ZW5jb2RlX3RhZyI6Im9lcF9oZCJ9&_nc_ht=scontent-arn2-2.xx&oh=0514643a069fbed5a4bc74153e4ebc05&oe=5D4D13F5")); break;

Yggdrasills commented 5 years ago

Replies to one message about 10 times. If I send something else when sending a video, then it is sent multiple times. What if the script scrolls many times? die () and exit () don't help. The server itself sends many requests to the script. Sending pictures via ImageMessage everything works as it should, but not with VideoMessage ...

o2-web commented 5 years ago

Replies to one message about 10 times. If I send something else when sending a video, then it is sent multiple times. What if the script scrolls many times? die () and exit () don't help. The server itself sends many requests to the script. Sending pictures via ImageMessage everything works as it should, but not with VideoMessage ...

understood. This is because Facebook is waiting for a response and if there is no response within a few seconds then it sends the request again. The send (Video) function takes a few seconds to process.

I solved this problem this way. On any webhook message I immediately respond response 200 ok and put the processing in the queue