Coder Social home page Coder Social logo

haj / twilio-gas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from illiatdesdindes/twilio-gas

0.0 3.0 0.0 184 KB

A Google Apps Script Twilio helper library.

Home Page: https://github.com/illiatdesdindes/twilio-gas

License: MIT License

JavaScript 100.00%

twilio-gas's Introduction

twilio-gas

A Google Apps Script Twilio helper library. Based on the twilio-node library.

Currently only RestClient and TwimlRepsonse modules have been adapted. Further work is needed to adpat the Capability module, as it depends on node-jwt-simple which also needs to be adapted to Apps Script.

Contributions are welcomed !

! Caution Alpha Work !

####Dependencies

Install

fork the repo or use directly this copy of the twilio-gas library in your own project. Use the project key:

MJluEaWRLspBmhL09uKHPtNf9UcAuUuPd

Here's how to use a library in Google Apps Script.

if you experience any issues with this project key. First ensure your using the last version of the library. Otherwise feel free to report your bug in the issues section.

Getting Started

var account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy';

var client = new twiliogas.RestClient(account_sid, auth_token);

// DO STUFF...

###Getting Started With REST

####Send An SMS

client.sendSms({
    to:'+16515556677', // Any number Twilio can deliver to
    from: '+14506667788', // A number you bought from Twilio and can use for outbound communication
    body: 'word to your mother.' // body of the SMS message
});

####Make a Phone Call

client.makeCall({

    to:'+16515556677',
    from: '+14506667788',
    url: 'http://www.example.com/twiml.php' // A URL that produces an XML document (TwiML) which contains instructions for the call

}, function(err, responseData) {

    //executed when the call has been initiated.
    Logger.log(responseData.from); // outputs "+14506667788"

});

###Getting Started With TwiML

var resp = new twiliogas.TwimlResponse();

resp.say('Welcome to Acme Customer Service!')
    .gather({
        action:'http://www.example.com/callFinished.php',
        finishOnKey:'*'
    }, function() {
        this.say('Press 1 for customer service')
            .say('Press 2 for British customer service', { language:'en-gb' });
    });

Logger.log(resp.toString());

Will output :

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>Welcome to Acme Customer Service!</Say>
    <Gather action="http://www.example.com/callFinished.php" finishOnKey="*">
        <Say>Press 1 for customer service.</Say>
        <Say language="en-gb">Press 2 for British customer service.</Say>
    </Gather>
</Response>

Or through ContentService deploying your script as a webapp :

function doGet() {
  var resp = new twiliogas.TwimlResponse();

  resp.say('Welcome to Twilio!');
  resp.say('Please let us know if we can help during your development.', {
    voice:'woman',
    language:'en-gb'
  });

  return ContentService.createTextOutput(resp.toString()).setMimeType(ContentService.MimeType.XML)
}

###Complete Working Example In your Google Apps Script editor :

var twilioNumber =   '+12345678900'; // your twilio phone number
var myPhoneNumber =  '+12345678911'; // your phone number
var myFriendNumber = '+12345678922'; // your friend phone number

function startCall() {
  var client = new twiliogas.RestClient('TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN');
  
  client.makeCall({
    from: twilioNumber,
    to: myPhoneNumber,
    url: ScriptApp.getService().getUrl()
  });
}

function doPost() {
  var resp = new twiliogas.TwimlResponse();

  resp.say('Google Apps Script will now connect you to your friend.');
  resp.dial(myFriendNumber);
  return ContentService.createTextOutput(resp.toString()).setMimeType(ContentService.MimeType.XML)
}

Next, deploy your script as a webapp. Set :

  • "Execute the app as" to "me ([email protected])"
  • "Who can acces to the app" to "Anyone, even anonymous"

Then execute "startCall" function.

Don't forget to deploy the latest version of your work evry time you want to test against Twilio's api.

More Information

For more detailed examples you have the twilio-node documentation.

TO DO

  • testing
  • adapt validateRequest() function
  • adapt node-jwt-simple
  • adapt Capability Token Generator

twilio-gas's People

Contributors

illiatdesdindes avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.