eva-library / channel-whatsapp

Twilio connector that allows you to connect eva with whatsapp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

N|Solid

Pre-requisites

Create account Twlilio

The first thing we must do is create an account in Twilio.

Once the account is created, we go to the Functions option and create one.

Create Function
Function Name sendMessage
Path URL_TWILIO/sendMessage

And in the option code insert a similar code.

const axios = require('axios');
const { escape } = require('querystring');
let sessions = {};
exports.handler = function (context, event, callback) {
    let twiml = new Twilio.twiml.MessagingResponse();
    let query = decodeURIComponent(escape(event.Body));
    let number1 = escape(event.From);
    let mediaContent = ''
    let link = ''
    if(event.MediaContentType0 == "application/pdf"){
        query = query+' Link del pdf '
        link = event.MediaUrl0
    }else if(event.MediaUrl0){
        const image = event.MediaUrl0
        const type = event.MediaContentType0
        mediaContent = {
            image,
            type
        }
    }
    const number = number1.slice(14);
    let inputText = query.replace(/%20/g, " ");
    console.log(number)
    const body = {
        "text": query,
        "phoneNumber": number,
        "userChannel": 'twilio',
        "mediaUrl": mediaContent,
        "mediaLink": link
    };
    let headers = {
        'Content-Type': 'application/json'
    };
    console.log(body);
    axios.post('URL_TO_SERVICE_POST/api/wsp/receive', body, { headers: headers });
}

We modify the whatsapp connector. Open the messagesAPI.js file and find the variables

  • accountSid
  • authToken

N|Solid

And replace with the credentials that your twilio account gives you.

With all the connector variables modified, it only remains to deploy the code in any cloud (Azure, GCP, Aws, etc..)

Thanks!

eva professional services

*Components are not supported

About

Twilio connector that allows you to connect eva with whatsapp


Languages

Language:JavaScript 100.0%