I need some help configuring Corvid to start a Twilio studio flow that I have configured. Basically, I am taking the phone number a user inputs on my site, then wanting to push it to Twilio where I have a message flow built out. I have verified the Twilio flow is functioning, but I can’t seem to get this flow to start after inputting information on my site. Any suggestions on how to accomplish this?
I have installed the Twilio npm packages and have been using the guide on here with the name [ Require() doesn’t work] (I apologize I am un able to post links on my account)
but to no avail.
Any idea what I am doing wrong and how to correct this?
Front end (home page)
import {sendSms} from 'backend/twilioSms';
export function button1_click(event) {
const msg = '#input11'; //#input11 is the phone number field on my website form
const number = '+xxxxMyTwilioNumberxxxx' //this is the number you want to send it to
sendSms(msg, number);
}
export function checkbox1_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
}
Backend
import Twillo from 'twilio';
const accountSid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //your accountSid
const authToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // your authToken
const client = require('twilio')(accountSid, authToken);
client.studio.flows('ht t p s ://studio. twilio .com/v2/Flows/xxxxxxxxxxxxxxxxxxxx/Executions')
.executions
.create({to: '#input11', from: 'xxxxMyTwilioNumberxxxx'})
.then(execution => console.log(execution.sid));
You have serval mistakes:
First you need to put the backend code in a jsw file (not js).
Then you have to add an export, maybe something like (see in blue ):
import Twillo from 'twilio';
const accountSid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //your accountSid
const authToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // your authToken
const client = require('twilio')(accountSid, authToken);
export function sendSMS(msg, number){
return client.studio.flows(/*Look at their documentation and see what should come here*/)
.executions
.create({to: '#input11', from: 'xxxxMyTwilioNumberxxxx'})
.then(execution => "done");
}
On the front end you should import the function:
import {sendSMS} from 'backend/twillio.jsw';
export function button1_click(event) {
const msg = $w('#input11').value; //I'm not sure what you're doing here, Shouldn't it be a message?
const number = '+xxxxMyTwilioNumberxxxx' ;//use real number
sendSms(msg, number);
}
But it’s really unclear what you’re trying to do, what are these 2 numbers on the front end? where is the message? Why don’t you use the parameters from the front end on the back end? etc…
Without clarifying that and adjusting the code in accordance it’s not going to work.
@jonatandor35 Hey thanks for the quick reply! I must say, I have absolutely no idea what I am doing programming-wise. I appreciate you taking a look… I am just trying things out and trying to get a small personal project up and running.
As far as what I am trying to do, I have a registration form on my Wix website (Name and phone #). What I would like to do is take that phone number that is collected, then push it over to Twilio. From there, I have a message flow in Twilio that I would like to be returned to the phone number we collected on the website.
They enter a phone# on our site → send that collected # to Twilio → Have Twilio say “Hey it looks like 555-555-5555 signed up on the website, let’s send them this message flow”.
I was able to build this out completely in Squarespace using Zappier as the middle man. However, I like the flexibility of Wix’s web design a bit more and if possible would like to cut out Zappier.
Anyway, I hope that clarifies anything I may have left out before.
Give me just a bit and I will try the corrections you posted.
@kazlcampbell so you’ll have to make some effort and read the documentation to understand what’s going on.
I use Twilio to send simple SMS messages but I’ve never used Twilio studio flow, so I can’t help you if you don’t know the basics (and as a matter of fact, it’s not even related to this forum as the knowledge you need is in the Twilio area).