![]() Now navigate back to your WhatsApp Sandbox on your Twilio Console and head to the Sandbox settings tab on the top. Copy the URL as it will be needed to be plugged into the WhatsApp sandbox settings. You’ll see that ngrok has generated a Forwarding URL to your local server on port 3000. Navigate back to your terminal and run the following command to run the index.js file:Īfter entering the command, your terminal will look like the following: ![]() However, to simplify the deployment for this tutorial, you’ll be deploying your app on your computer. In a production environment, it’s recommended to run your Node.js application on a cloud server. The returned response is a message from the assistant (the impersonator) which gets appended to the users message array and then is used in the return statement which is passed back to the message handler to be sent back to the user. The code will construct a messageObj object and append it to the users messages property in the “database”.įinally, using the users message array, it is plugged into OpenAI’s createChatCompletion function which calls their API to generate chat completion. If the above two conditions weren’t met, the incoming message should be a part of an ongoing conversation since the user should already be in the “database”. Although the user did not text ‘hey’, the ‘hey’ message is intended to start off the conversation and have the assistant introduce themselves. It will then add the system message, which tells the assistant who to impersonate, and a ‘hey’ message from the user to the users messages property in the “database”. If the user's message contained " impersonate", the code will then parse the individual the assistant should impersonate and store it in the user's object in the “database” and reset the past conversations (if there were any). If no user was found in the “database” and the user did not include an individual for the assistant to impersonate, the application will return a default message stating, “Text ‘Impersonate' followed by the individual you'd like me to impersonate". This works when the user texts the WhatsApp number “Impersonate” followed by the individual they'd like the assistant to impersonate e.g “Impersonate Einstein”. ![]() It will then check to see if the user asked the assistant to impersonate a famous personality. The function starts off by fetching the user from the “database” (the users object we set up earlier). I wrote the SMS form processor to allow sending SMS messages one-at-a-time or in bulk using newline delimited phone = async function generatePersonalityResponse(message, number) ) Res.send(JSON.stringify(error, undefined, 2)) Īpp.post('/fetch-inbound', (req, res) => ),ĭate = moment(date).format('YYYY-MM-DD HH:mm:ss') Res.send(JSON.stringify(message, undefined, 2)) I created routes for sending an SMS message, and for fetching inbound/outbound communications.Ĭonst accountSid = 'MY-TWILIO-ACCOUNT-SID' Ĭonst authToken = 'MY-TWILIO-AUTH-TOKEN' Ĭonst client = require('twilio')(accountSid, authToken) Ĭonst my_number = 'MY-TWILIO-PHONE-NUMBER' Next, I modified app.js in the root of the app folder to add my Twilio API credentials, and routes to the API client. The end result is a page with 4 navigation tabs that allow sending a single SMS, sending SMS in bulk, seeing the status of sent SMS messages, and fetching the inbound call/SMS log.įirst I installed express and express-generator and used it to generate an app skeleton. ![]() With that in mind, I made a simple frontend to the Twilio API. We’re starting to use Twilio at work for communicating with customers, and there was a need for a tool that would allow us to send SMS messages and check the history of calls and messages to the phone number we’re sending from. The API has solid documentation for a number of programming languages, which makes it easy to develop with. I really like Twilio as a service for programmatically sending and receiving SMS messages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |