How to use scripting API to generate Tropo API keys

Built.io Flow Cisco Tropo actions that let you automate phone calls and text messages, and integrate them with your applications. However, to use these actions, you will need to create an application in your Cisco Tropo account. Once you have created an application, you get the API keys for that particular application. These API keys are used while creating a connection through which Built.io Flow can access that specific application. 

It is important to note that all Cisco Tropo applications are standalone and, hence, you will need to create a separate connection for each application while using them in any particular workflow. 

Let us understand how to create an application and retrieve its API keys with the help of an example. Let’s say you wish to create an application that sends text messages to a specific recipient. To do this, follow the steps given below:

Step 1. Log in


Log-in to your Cisco Tropo account. If you have not created an account yet, click on 'Register' to create one. 

Step 2. Create App


After you have logged-in to your Tropo account, click on My Apps > Create New App.  You will be redirected to a new window. 

 Enter the following details. 

   - Basic Information (Mandatory): Provide a unique name for your application. For example, Sample App.

   - Type of Application (Mandatory): Select the 'Scripting API' option. You will need o write/select an application script that can be hosted on Tropo server. 

Click on 'New Script' option to write a new script for application or click on 'Select my files' option to use existing scripts saved in your Tropo account. 

1-app-create

Click on 'New Script' option. You will be redirected to a new console window. You will need to write the script for your application in this console. Once you have written the script, enter a suitable name for the script along with a proper extension and click on 'Save'. You will be redirected to the main window. 

 Next, enter the phone number details.

   -  Phone Number (Optional): Add your phone number to your application by selecting the 'Country' and 'Region' from the drop-down lists. 

Once you have entered all the details, click on 'CREATE APP'

2-phone-number

With this step, a new application will be created in your Tropo account. 

Step 3. Write Scripts


You will be redirected to the new window where you can see/update the settings for your application as shown below:

3-details-window

You will notice that the both the 'Voice Script' and 'Text Script' have same name, and they contain the same application script you had written/added earlier. This will result in scripts overwriting each other when they are called. To avoid this, you will need to edit the names and scripts as per your requirements. 

Add Voice Script:

Click on 'Edit Script' link given beside 'Voice Script' tab and write the voice script in the console window that opens. Given below is the sample voice script for our example.

opt = {

   timeout      : 120,

   network      : network,

   onAnswer     : function() {

       say(msg);

   },

   onTimeout    : function() {

       log("Call timed out " + (new Date()).toString() + ' to contact ' + numberToDial);

   },

   onCallFailure: function() {

       log("Call could not be completed as dialed " + (new Date()).toString() +  ' to contact ' + numberToDial);

   },

   onBusy       : function() {

       log("Recepient busy " + (new Date()).toString() + ' to contact ' + numberToDial);

   }

};

if(typeof(callerID) !== 'undefined'){

    opt.callerID = callerID;

}

call([numberToDial], opt);

4-voice-script

After you have clicked on 'Save', you will be redirected to the main window. 

Alternatively, you can click on ‘Select my files’ option to upload an existing script. Once you are done writing the script, save it with a suitable file name and appropriate extension. 

Add Text Script:

Enter a new name for text script file along with the extension ('Demo.js' in this example) . Click on the 'Edit script' link and write the script in the console window that opens. Given below is the sample text script for our example.

message(msg, {

    to:numberToDial,

    network:"SMS"

});

5-sms-script

After you have clicked on 'Save', you will be redirected to the main window. 

Alternatively, you can click on ‘Select my files’ option to upload an existing script. Once you are done writing the script, save it with a suitable file name and appropriate extension. 

Now when you click on the ‘Save Settings’ button, the changes will be reflected in your Cisco Tropo account as shown below:

6-scripts


Step 4. Get API Keys


On the Settings page, under API keys, you will be able to get the ‘voice’ as well as ‘messaging’ API keys. You can use these API keys while creating a connection for this application in Built.io Flow.

7-api-key