mattmezza / vue-beautiful-chat

A simple and beautiful Vue chat component backend agnostic, fully customisable and extendable.
https://matteo.merola.co/vue-beautiful-chat/
MIT License
1.5k stars 441 forks source link

How to get the media file url and send it through Twillo chat ? #215

Closed arsh-amar closed 3 years ago

arsh-amar commented 3 years ago

Following is the code to send media through Twillo

// example for sending media message as FormData // --------------------------------------------- const formData = new FormData(); formData.append('file', $('#formInputFile')[0].files[0]); // get desired channel (for example, with getChannelBySid promise) chatClient.getChannelBySid(channelSid).then(function(channel) { // send media with all FormData parsed atrtibutes channel.sendMessage(formData); });

// example for sending media message as String // ------------------------------------------- // get desired channel (for example, with getChannelBySid promise) chatClient.getChannelBySid(channelSid).then(function(channel) { // send SVG image as string with content type image/svg+xml; charset=utf-8 channel.sendMessage({ contentType: 'image/svg+xml; charset=utf-8', media: '' + '<path d="M50,3l12,36h38l-30,22l11,36l-31-21l-31,21l11-36l-30-22h38z"' + ' fill="#FF0" stroke="#FC0" stroke-width="2"/>', }); });

// example for sending media message as Buffer // ------------------------------------------- // get desired channel (for example, with getChannelBySid promise) chatClient.getChannelBySid(channelSid).then(function(channel) { // send PNG image as Buffer with content type image/png channel.sendMessage({ contentType: 'image/png', media: fs.readFileSync(pngFile), }); });

github-actions[bot] commented 3 years ago

Thanks for opening up your first issue!

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.