Skip to content

Instantly share code, notes, and snippets.

@saket424
Last active December 16, 2015 22:26
Show Gist options
  • Save saket424/cab1ea587fab3a724d7d to your computer and use it in GitHub Desktop.
Save saket424/cab1ea587fab3a724d7d to your computer and use it in GitHub Desktop.
AT&T DevSummit Call Management API node-red sample flow

This file documents a sample node-red flow that can be imported into node-red or AT&T flow Designer or IBM Bluemix and illustrates a sample flow that involves obtaining the appropriate OAUTH credentials, making a sample call and also subscribing/processing a call direction flow
More details can be found at the website below
http://foundry.att.net/index.php/oauth-token/
http://foundry.att.net/index.php/apis/call-control/
http://foundry.att.net/index.php/apis/call-direction/

Paste the flow.json using Import->From ClipBoard and then modify the globals
{
context.global.number1="404724XXXX";
context.global.number2="404724YYYY";
context.global.number3="404724ZZZZ";
context.global.client_id="Enter-client_id-here";
context.global.client_secret="Enter-client_secret-here";
context.global.base_url="http://api.foundry.att.net:9001";
context.global.callback_url="http://api-flow.att.io/sandbox/your-flow-name/your-username/in/flow/dosomething";
}
Then deploy the flow either on the AT&T Flow Designer sandbox or on a Bluemix node-red instance
Step 0 Globals are initialized as indicated above
Step 1 An oauth token is generated and used in the remaining flows
Step 2 A 1-party call is made to number 1 and then hung up after 15 seconds
Step 3 A call directiion subscription is placed on number2 and calls to number2 are instead routed to number3 when the callback is received
Step 4 the call direction subscription can be deleted

[{"id":"5c39017e.a3c7","type":"comment","z":"73357e0a.8cca8","name":"Process to get and store a bearer access_token","info":"","x":192,"y":108,"wires":[]},{"id":"bc55ce7.f43aa3","type":"inject","z":"73357e0a.8cca8","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":147,"y":139,"wires":[["608ded1f.9f7214"]]},{"id":"610d4600.9ef2b8","type":"debug","z":"73357e0a.8cca8","name":"","active":true,"console":"false","complete":"true","x":588,"y":268,"wires":[]},{"id":"44fbe42b.bb041c","type":"function","z":"73357e0a.8cca8","name":"","func":"context.global.BearerToken=msg.payload.access_token;\nnode.log(context.global.BearerToken);\nconsole.log(\"Bearer: \" + context.global.BearerToken);\n//var msg ={ \"payload\":\"Done\"}\nreturn msg;","outputs":1,"noerr":0,"x":551,"y":133,"wires":[[]]},{"id":"608ded1f.9f7214","type":"function","z":"73357e0a.8cca8","name":"GetOAuthToken","func":"var newMsg ={\n \"url\":context.global.base_url+\"/oauth/client_credential/accesstoken?grant_type=client_credentials\",\n \"method\": \"POST\",\n \"headers\": {\n \"Content-Type\":\"application/x-www-form-urlencoded\"\n },\n \"payload\": \"client_id=\"+context.global.client_id+\"&client_secret=\"+context.global.client_secret\n \n}\nreturn newMsg;\n","outputs":1,"noerr":0,"x":344,"y":147,"wires":[["1d90326c.e26fce"]]},{"id":"1d90326c.e26fce","type":"http request","z":"73357e0a.8cca8","name":"","method":"use","ret":"obj","url":"","x":450,"y":229,"wires":[["610d4600.9ef2b8","44fbe42b.bb041c"]]},{"id":"2e70f40f.d18f0c","type":"function","z":"73357e0a.8cca8","name":"","func":"var newMsg1 ={\n \"url\":context.global.base_url+\"/a1/nca/callcontrol/call/\"+context.global.number1,\n \"method\": \"POST\",\n headers: {\n \"Content-Type\":\"application/json\",\n \"Authorization\":\"Bearer \"+context.global.BearerToken,\n \"User-Agent\":\"NodeRed-Rapport\"\n },\n payload: {\n \"p1_displayName\":\"Anand\",\n \"announcement\":\"http://cb.setlurs.com/files/q.wav\"\n }\n}\nreturn newMsg1;","outputs":1,"noerr":0,"x":295,"y":381,"wires":[["3d225e04.c2dda2","bb992d9e.4466d"]]},{"id":"9c42a698.63bd58","type":"inject","z":"73357e0a.8cca8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":374,"wires":[["2e70f40f.d18f0c"]]},{"id":"3d225e04.c2dda2","type":"http request","z":"73357e0a.8cca8","name":"","method":"use","ret":"obj","url":"","x":479,"y":377,"wires":[["828fcad7.7d7038","bb992d9e.4466d"]]},{"id":"bb992d9e.4466d","type":"debug","z":"73357e0a.8cca8","name":"","active":true,"console":"false","complete":"true","x":539,"y":471,"wires":[]},{"id":"828fcad7.7d7038","type":"function","z":"73357e0a.8cca8","name":"","func":"context.global.sessionId=msg.payload.sessionId;\nnode.log(context.global.sessionId);\nconsole.log(\"sessionId: \" + context.global.sessionId);\n//var msg ={ \"payload\":\"Done\"}\nreturn msg;","outputs":1,"noerr":0,"x":567,"y":316,"wires":[["3fefa566.c0105a"]]},{"id":"670e3bea.98f1c4","type":"function","z":"73357e0a.8cca8","name":"InitializeGlobals","func":"//if (typeof context.global.number1 === 'undefined')\n{\n context.global.number1=\"404724XXXX\";\n context.global.number2=\"404724YYYY\";\n context.global.number3=\"404724ZZZZ\";\n context.global.client_id=\"enter-your-client_id-here\";\n context.global.client_secret=\"enter-your-client_secret-here\";\n context.global.base_url=\"http://api.foundry.att.net:9001\"\n context.global.callback_url=\"http://enter-your-callback-url-here\"\n}\n","outputs":1,"noerr":0,"x":385,"y":56,"wires":[[]]},{"id":"3fefa566.c0105a","type":"delay","z":"73357e0a.8cca8","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":94,"y":502,"wires":[["ef0c58a2.10f3a8"]]},{"id":"ef0c58a2.10f3a8","type":"function","z":"73357e0a.8cca8","name":"","func":"var newMsg2 ={\n \"url\":context.global.base_url+\"/a1/nca/callcontrol/manage/\"+context.global.sessionId,\n \"method\": \"DELETE\",\n headers: {\n \"Authorization\":\"Bearer \"+context.global.BearerToken,\n \"User-Agent\":\"NodeRed-Rapport\"\n }\n}\nreturn newMsg2;","outputs":1,"noerr":0,"x":259,"y":500,"wires":[["10bed7bf.ef4128"]]},{"id":"10bed7bf.ef4128","type":"http request","z":"73357e0a.8cca8","name":"","method":"use","ret":"txt","url":"","x":404,"y":501,"wires":[["bb992d9e.4466d"]]},{"id":"67681f56.9897e","type":"inject","z":"73357e0a.8cca8","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":109,"y":620,"wires":[["e34bb3fa.1cb45"]]},{"id":"e34bb3fa.1cb45","type":"function","z":"73357e0a.8cca8","name":"","func":"var newMsg1 ={\n \"url\":context.global.base_url+\"/a1/nca/subscription/callDirection/+1\"+context.global.number2,\n \"method\": \"POST\",\n headers: {\n \"Content-Type\":\"application/json\",\n \"Authorization\":\"Bearer \"+context.global.BearerToken,\n \"User-Agent\":\"NodeRed-Rapport\"\n },\n payload: {\n \"addressDirection\": \"Called\",\n \"criteria\": [\"CalledNumber\"],\n \"url\": context.global.callback_url\n }\n}\nreturn newMsg1;","outputs":1,"noerr":0,"x":296,"y":638,"wires":[["48ac8337.b7537c"]]},{"id":"48ac8337.b7537c","type":"http request","z":"73357e0a.8cca8","name":"","method":"use","ret":"obj","url":"","x":487,"y":637,"wires":[["80702715.7f8fd8","532e0c49.acd1f4"]]},{"id":"80702715.7f8fd8","type":"function","z":"73357e0a.8cca8","name":"","func":"context.global.subId=msg.payload.subId;\nnode.log(context.global.subId);\n//var msg ={ \"payload\":\"Done\"}\nreturn msg;","outputs":1,"noerr":0,"x":599,"y":581,"wires":[[]]},{"id":"e41e21a2.1be1e","type":"comment","z":"73357e0a.8cca8","name":"this is a sample call direction subscription creation","info":"","x":215,"y":572,"wires":[]},{"id":"75408fa7.8abf7","type":"comment","z":"73357e0a.8cca8","name":"Click2call to one participant followed by a hangup","info":"","x":187,"y":255,"wires":[]},{"id":"fadfdc56.05202","type":"inject","z":"73357e0a.8cca8","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":107,"y":739,"wires":[["e613104e.19ecf"]]},{"id":"e613104e.19ecf","type":"function","z":"73357e0a.8cca8","name":"","func":"var newMsg1 ={\n \"url\":context.global.base_url+\"/a1/nca/subscription/callDirection/\"+context.global.subId,\n \"method\": \"DELETE\",\n headers: {\n \"Authorization\":\"Bearer \"+context.global.BearerToken,\n \"User-Agent\":\"NodeRed-Rapport\"\n }\n}\nreturn newMsg1;","outputs":1,"noerr":0,"x":299,"y":733,"wires":[["91102324.6eefe"]]},{"id":"532e0c49.acd1f4","type":"debug","z":"73357e0a.8cca8","name":"","active":true,"console":"false","complete":"true","x":590,"y":700,"wires":[]},{"id":"91102324.6eefe","type":"http request","z":"73357e0a.8cca8","name":"","method":"use","ret":"txt","url":"","x":435,"y":745,"wires":[["532e0c49.acd1f4"]]},{"id":"cbc2b0b2.343d5","type":"http in","z":"73357e0a.8cca8","name":"","url":"/dosomething","method":"post","swaggerDoc":"","x":98,"y":816,"wires":[["c144acd4.3ebb5","913f991e.6ec068"]]},{"id":"c144acd4.3ebb5","type":"function","z":"73357e0a.8cca8","name":"","func":"node.log(msg.payload);\nmsg.headers = {\n \"Content-Type\":\"application/json\"\n };\nmsg.payload = { \"action\": {\n \"actionToPerform\": \"Route\",\n \"routingAddress\": \"sip:+1\"+context.global.number3+\"@foundry.att.net;display=originator\"\n}};\nmsg.statusCode=200;\nreturn msg;","outputs":1,"noerr":0,"x":282,"y":818,"wires":[["db4686a0.24b978"]]},{"id":"db4686a0.24b978","type":"http response","z":"73357e0a.8cca8","name":"","x":461,"y":821,"wires":[]},{"id":"913f991e.6ec068","type":"debug","z":"73357e0a.8cca8","name":"","active":true,"console":"false","complete":"payload","x":321,"y":899,"wires":[]},{"id":"9e8dcd1e.61723","type":"inject","z":"73357e0a.8cca8","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":101,"y":58,"wires":[["670e3bea.98f1c4"]]},{"id":"c6cf1fc7.3930e","type":"comment","z":"73357e0a.8cca8","name":"Initialize Global variables used in the flows","info":"","x":141,"y":20,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment