GithubHelp home page GithubHelp logo

isabella232 / nodejs-ttscalloutexample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sinch/nodejs-ttscalloutexample

0.0 0.0 0.0 213 KB

Shows how to use Sinch rest API with nodejs to make Text to speech callouts

JavaScript 100.00%

nodejs-ttscalloutexample's Introduction

Send OTP codes with text to speech calls using Sinch and Node.js

In this tutorial I will show you how to use node.js to build a text to speech call that reads out pin-codes. To read more about the Sinch callout API please see the documentation.

Other use cases

Common use cases for this type of call are weather- and fraud alerts, when you suspect that an SMS is not delivered.

What you need to get started

  • Node development environment
  • Application- key and secret. Get one here if you don't have one already - Sign up.
  • Some credits on your account. Set up your phone on the dashboard and my boss will give you $2 to get you started!

Code

For this code snippet I will use the sinch-request npm package to sign the requests. This package is not required but it makes life a lot easier. Below code makes a call to +15551234567 and play "Your pin code is 1234" in US English when user is answering the call.

var sinchRequest = require('sinch-request');
var https = require('https');

var creds = { key: 'your key',
  secret: 'your secret'
};

var bodyData = JSON.stringify({ method: 'ttsCallout',
  ttsCallout:
   { destination: { type: 'number', endpoint: '+15551234567' },
     domain: 'pstn',
     custom: 'customData',
     locale: 'en-US',
     prompts : "#tts[Your pin code is 1234]", } });

var options = {
  method: 'POST',
  host: 'callingapi.sinch.com',
  port: 443,
  path: '/v1/callouts',
  data: bodyData
};

sinchRequest.applicationSigned(options, creds);
var req = https.request(options, function(response) {
  var data = '';
  response.on('data', function (chunk) {
    data += chunk;
  });
  response.on('end', function () {
    console.log('Response body: ' + data);
    //here you can i.e save your callid,
  });
});
req.end(options.data);

Next steps

In the next tutorial I will show you how to make IVR menus that enable you to collect input from the user.

nodejs-ttscalloutexample's People

Contributors

spacedsweden 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.