Giter Club home page Giter Club logo

tropo-webapi-node's Introduction

Tropo WebAPI Node.js Library

A Node.js module for the Tropo WebAPI.

Installation

To get started you will first need to have Node.js installed. Howtonode has a good write-up on installing Node.js on Windows, Ubuntu and OSX.

If you have Node.js installed, and are using the Node Package Manager (npm), just do:

~$ npm install tropo-webapi -g

If you install with npm, then you can reference the tropo Node library in your node.js scripts like this:

require('tropo-webapi');

If you do not have npm installed, then you will then want to create a directory for your project, you may want to use a convention like this:

	./project
	|-lib
	|-public
	|--css
	|--js
	|-vendor

Add this declaration to your server.js starting file

	var tropowebapi = require('tropo-webapi');

Running

You may then run your script from within the project directory with:

	node server.js

Sample Usage

Generate a JSON Doc

	var tropowebapi = require('tropo-webapi');
	var sys = require('sys');

	var tropo = new tropowebapi.TropoWebAPI(); 

	tropo.say("Hello, World.");

	sys.puts(tropowebapi.TropoJSON(tropo));

Respond to a Tropo WebAPI Session

	/**
	* A very simple node web server that will respond to requests
	* with the Tropo WebAPI JSON version of "Hello, World!" 
	*/

	var http = require('http');
	var tropowebapi = require('tropo-webapi');

	var server = http.createServer(function (request, response) {

		// Create a new instance of the TropoWebAPI object.
		var tropo = new tropowebapi.TropoWebAPI(); 
		tropo.say("Hello, World!");

		// Render out the JSON for Tropo to consume.
		response.writeHead(200, {'Content-Type': 'application/json'});
		response.end(tropowebapi.TropoJSON(tropo));

	}).listen(8000); // Listen on port 8000 for requests.

Samples

You may run the included samples from within the tropo-webapi-node directory as follows:

	node samples/hello-word-http.js

We have also included several examples for the Express.js Node framework. This may be run from within the tropo-webapi-node library as follows:

	node samples/express/hello-world.js

tropo-webapi-node's People

Contributors

akalsey avatar akalyan avatar chrismatthieu avatar colby-6sco avatar jharlap avatar jpjpjp avatar jsgoecke avatar kevinbond avatar krsboone avatar mheadd avatar pengxli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tropo-webapi-node's Issues

This may be an understanding issue, but cannot get parameters out of session JSON without using express

http://gist.github.com/a17735b0fc82c78fe8ab

Gets stuck when I define multiple levels to get to the parameter, like so:

var to = session.parameters.numbertodial;

/Users/justindupree/Sites/tropo-webapi-node/samples/node_sample.js:17
var to = session.parameters.numbertodial;
^
TypeError: Cannot read property 'numbertodial' of undefined
at IncomingMessage. (/Users/justindupree/Sites/tropo-webapi-node/samples/node_sample.js:17:30)
at IncomingMessage.emit (events.js:61:17)
at HTTPParser.onMessageComplete (http.js:132:23)
at Socket.ondata (http.js:1007:22)
at Socket._onReadable (net.js:678:27)
at IOWatcher.onReadable as callback

Could I be doing something wrong?

Headers parameter missing for transfer()

Unable to change headers using WebAPI. The parameter does not exist as shown below:

Transfer = function(to, answerOnMedia, choices, from, name, on, required, timeout)

It just needs to be added. Thank you!

session not supported?

strange but i saw that session is not supported.
Maybe it is stupid question but haw cal i take caller id ?

cheers,
G.P.

Passing in parameters does not seem to work with "var session = Session(json);"

Only way we could get it to work:

request.addListener('end', function() {

    var session = JSON.parse(json);
    var tropo = new TropoWebAPI();

    var to = session.session.parameters.numbertodial;
    var name = session.session.parameters.customername;
    var msg = session.session.parameters.msg;

    tropo.call(to);
    tropo.say("OMG " + name + ", " + msg + "!");

    response.end(TropoJSON(tropo));
});

Unable to extract header using getHeader();

Here is a tropo scripting application that gets called and sets the x-callername in the header.

<?php

say("Hello. , , , tranferring");
transfer('sip:[email protected]', array( 
    'headers' => array('x-callername' => "Kevin Bond")
    ));
?>

This is followed by the WebAPI app that attempts to retrieve a x-callername header from the session object.

<?php

require 'tropo-webapi-php/tropo.class.php';

$session = new Session();
$tropo = new Tropo();

$tropo->say("you got transfered");
$getHeader = $session->getHeaders();

$tropo->say("Hello " . $getHeader->x_callerName);

$tropo->RenderJson();
?>

You can check the logs here to see what went on here

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.