I am trying to respond to incoming sms messages with Apps Script through Twilio. I have done all the steps exactly as in the video below.
https://youtu.be/j0wjM1Ds3lc
I currently have a doGet function to handle incoming sms messages. In my Twilio number settings under messaging I have set the incoming messages with a GET webhook to the published apps script url.
When I send a sms message to my Twilio number, I can see the message was received in the Twilio logs but nothing happens in the apps script.
The apps script is published as 'anyone even anonymous' can execute. In the apps script logs I can see that the script is not being executed.
I have sms capabilities on Twilio number.
Any help would be greatly appreciated. I apologize if this is something simple I missed.
function doGet(e) {
var incoming = e.paramater.Body;
var translated = LanguageApp.translate(incoming, "en", "es")
var output = ContentService.createTextOutput(translated).setMimeType(ContentService.MimeType.TEXT);
return output
}
I expect to receive the translated message sent back to my number but currently the apps script is not being executed at all by Twilio.
Change
var incoming = e.paramater.Body;
to
var incoming = e.parameter.Body;
Also, make sure your Webhook is set to HTTP GET.
Related
We configure our phone numbers in Twilio to handle Voice Calls with a SIP Trunk that goes to our FreePBX server in our office.
My goal is to log all calls to a Google Sheet when they are completed. I have tried to set this up two ways:
Configure the Twilio number with: Webhook. Point the incoming call to a Google Apps Script webhook URL, the script logs the call, then return TwiML message to forward the call to my cell phone. This works to log the call to the Google Sheet, but then we cannot use our office FreePBX phone system to take the call since it is configured with Webhook rather than SIP Trunk (and forwarded to my cell rather than handled by the FreePBX server).
Here is that Google Apps Script code:
function doGet(args) {
var spreadsheetID = 'xxxxxxxxxxxxxxxxxxxx';
// Create a date object for the current date and time.
var now = new Date();
now = Utilities.formatDate(now, 'America/Chicago', 'yyyy-MM-dd\'T\'HH:mm:ss');
//Incoming parameters from Twilio. Documentation here: https://www.twilio.com/docs/voice/twiml
var callStatus = args.parameter.CallStatus;
var callerName = args.parameter.CallerName;
var fromNumber = args.parameter.From;
var toNumber = args.parameter.To;
var callDirection = args.parameter.Direction;
SpreadsheetApp.openById(spreadsheetID).appendRow([now, callStatus, callerName, fromNumber, toNumber, callDirection]);
var text = ContentService.createTextOutput("<Response><Dial>+14055991234</Dial></Response>").setMimeType(ContentService.MimeType.XML);
return text;
}
Again, this logs the call, but does not subsequently handle it with a Twilio SIP Trunk.
A Zapier trigger event for Twilio "New Call". This provides me a Webhook URL and the following instructions:
"Set up your Callback URL! Log into Twilio and visit your incoming numbers page, edit the number you want to trigger on, and paste the below URL into Call Status Changes. Click save!"
In order to place the Webhook URL into the Call Status Changes box in Twilio, the number must be configured in Twilio with Webhooks, but we are configuring with SIP Trunk. So I don't know how to use a SIP Trunk with our Twilio numbers and also use a Webhook for the Call Status Changes so I can log the calls to a Google Sheet.
Any guidance is appreciated.
Twilio Phone Numbers that are setup with Elastic SIP Trunking do not also trigger webhooks.
One way around this could be to turn on Voice Insights for your SIP trunk and use Event Streams to trigger a webhook. There are various different events available but I believe the gateway events (which are triggered by call progress events) would be the right ones to listen for and react on.
Alternatively, you could look to add something into your FreePBX installation that could trigger the update to the Google Sheet once your call is finished.
I am developing a add-on program in google app script which gets all the gmail sent mails with there subject, body, attachment(if any). I have did this for the Inbox mail using getInboxThreads() function. Is there a function which does same for sent mails?
The program that i am writing is for any gmail user or a group of users how wants to save their gmail emails on the google drive for monitoring or any other operations.
You can use the user.messages.list method to get a list of all the message ids for the user. You will then have to use user.messages.get To get the data about the message.
You can use the 'q': 'in:sent' parameter to get only the messages in the sent folder.
function myFunction() {
var myMessages=Gmail.Users.Messages.list("me",{'maxResults': 5 , 'q': 'in:sent' }).messages;
Logger.log(myMessages);
for(var i=0;i<myMessages.length;i++){
var id=myMessages[i].id;
Gmail.Users.Messages.get('me', id).payload.headers.forEach(function(e){
if(e.name=="Subject"||e.name=="From"){
Logger.log(e.name+": "+e.value)
}
}
);
}
}
Thank you #DalmTo
Your post help me lot.
I did some research got a similar but little bit different solution.
I found a method in GmailApp class called search and sent a query(in:sent) as you suggested. This returned me all the sent mails.
I did something like this
var _sentMail = GmailApp.search('in:sent');
This returned me array of GmailThread.
The one thing i did found that sent label in our gmail dashboard is not actually a label, its a method which takes a parameter "in:sent".
I'm new to this and trying to figure out the basics. I want to use google apps script to receive requests from slack and send back information from a spreadsheet.
I am stuck at this step. EventsAPI - URL Verification. My approach was to have a doPost() function that returns the challenge. After I was able to confirm slack could connect to the app I would be able to build it out to send the required information from the spreadsheet.
function doPost(e){
return ContentService.createTextOutput(JSON.parse(e.postData.contents).challenge);
}
I expect the challenge to be successfully returned and the URL verified.
The error I receive in Slack is Request URL Your URL didn't respond with the value of the challenge parameter.
Trying to receive an SMS at my Twilio number and send a POST request to a Google Apps Script app URL as a result of the received SMS.
I have this doPost() message:
function doPost(request) {
return ContentService.createTextOutput("User says: "+JSON.stringify(request));
}
Some text should be spit out containing the request data.
My doPost() method never gets called. I can't tell if the POST request is actually being sent by Twilio. I see in the Twilio number message log that my SMS is received by Twilio. But after that I can't tell. I have the Twilio number configured for webhook - HTTP POST, and the published URL of my Google Apps Script project. If I change that to HTTP GET my doGet() method DOES get called. I need to doPost() method called, though. any suggestions? TIA.
How about the following confirmation?
Confirmation points :
Redeploy Web Apps as a new version again.
When the script is updated, Web Apps is required to be redeployed as a new version for reflecting the update.
Confirm setting for Web Apps.
"Execute the app as:" is "Me".
"Who has access to the app:" is "Anyone, even anonymous".
Retrieve a log of request using Stackdriver.
The sample script is as follows. Please copy and paste it. And redeploy Web Apps.
Request POST.
On script editor, click View -> Stackdriver Logging
By this, when POST request is received, you can see the log.
Sample script :
function doPost(request) {
console.log(JSON.stringify(request)); // Here
return ContentService.createTextOutput("User says: "+JSON.stringify(request));
}
By above confirmation, the reason of your problem may be found. But if this was not useful for you, I'm sorry.
I decided to just use doGet(). See my response to the previous comment.
I already developed applicaton for google app script that can send email messages, but right now there is a need for me to send gtalk chat/xmpp message to user from my script.
my question is, is it possible for me to send gtalk chat/xmpp message directly from google app script? if it is not possible then is there any work around about this?
Basically, there are two types of messages you can automate through the App script.
Synchronous: building a boot that can respond to user inputs.
Asynchronous: specified trigger-based messaging systems. like submitting a google form or time-based.
Let's talk about Asynchronous
You can do it by Using incoming webhooks.
Create a Google Chart Room > Create a webhook URL. click_here
Use this Code:
function myFunction() {
var WebWhooklink = "PEST_YOUR_WEBHOOK_URL_HERE"
var message = { text: "Hello Chat"};
var payload = JSON.stringify(message);
var options = {
method: 'POST',
contentType: 'application/json',
payload: payload
};
var response = UrlFetchApp.fetch(WebWhooklink, options ).getContentText();
}
There is no built-in support for sending Google Chat messages. You can file a feature request on the issue tracker.
If you are able to make HTTP requests to external services from with in a google app script then you might be able to use an HTTP to XMPP gateway such as this:
http://chatmongers.com/blog/introducing-the-chatmongershttp-to-xmpp-gateway/
There would be a number of constraints you may still have to work through. The most common one being that privacy extensions block all messages from users that are not in the destination user's roster, but that's going to be a problem no matter how you manage to get XMPP messages sent.