Facebook allows bots to now send audio and video files to users which play directly inside the messenger. Also, bots can now send pdf files and doc files as an attachment .
Let's understand how to send these attachments from a bot built using Gupshup.
To send an audio clip, upload that clip on a server in mp3 format and then send it to the user using the JSON mentioned below.
{
"type": "audio",
"url": "https://a.clyp.it/v3rprye4.mp3"
}
Change the value of “url” as per your file location.
You need to send this JSON as a string and Gupshup will make it work behind the scene.
As per Facebook,the maximum allowed attachment size for audio is 10 MB.
If you were using the hosted code on the bot builder then the code to send this audio attachment is :
if(event.message=='audio'){
var audioObj = {
"type":"audio",
"url":"https://a.clyp.it/v3rprye4.mp3"
};
context.sendResponse(JSON.stringify(audioObj));
}
This is how it will render on Facebook messenger :
To send a video clip, upload that clip on a server and then send it to the user using the JSON mentioned below.
{
"type":"video",
"url":"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
}
Change the value of “url” as per your file location.
You need to send this JSON as a string and Gupshup will make it work behind the scene.
If you were using the hosted code on the bot builder then the code to send this video attachment is :
if(event.message=='video'){
var videoObj = {
"type":"video",
"url":"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
};
context.sendResponse(JSON.stringify(videoObj));
}
This is how it will render on Facebook messenger :
To send a file attachment, upload that file on a server and then send it to the user using the JSON mentioned below.
{
"type":"file",
"url":"http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf"
}
Change the value of “url” as per your file location.
You need to send this JSON as a string and Gupshup will make it work behind the scene.
If you were using the hosted code on the bot builder then the code to send this video attachment is :
if(event.message=='file'){
var fileObj = {
"type":"file",
"url":"http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf"
};
context.sendResponse(JSON.stringify(fileObj));
}
This is how it will render on Facebook messenger :