diff --git a/Campaign_Samples/js/bulk_get_campaigns.js b/Campaign_Samples/js/bulk_get_campaigns.js index 0f35456..c99340f 100644 --- a/Campaign_Samples/js/bulk_get_campaigns.js +++ b/Campaign_Samples/js/bulk_get_campaigns.js @@ -3,13 +3,18 @@ var accountSid = ""; var apiKey = "" var apiToken = ""; var encoding = Buffer.from(apiKey + ':' + apiToken).toString('base64') -var options = { method: 'GET', - url: 'https://api.exotel.com/v2/accounts/'+ accountSid +'/campaigns', - qs: { page_size: '1', page: '1' }, - headers: - { - Authorization: 'Basic ' + encoding, - 'Content-Type': 'application/json' } }; +var options = { + method: 'GET', + url: 'https://api.exotel.com/v2/accounts/' + accountSid + '/campaigns', + qs: { + page_size: '1', + page: '1' + }, + headers: { + Authorization: 'Basic ' + encoding, + 'Content-Type': 'application/json' + } +}; request(options, function (error, response, body) { if (error) throw new Error(error); diff --git a/Campaign_Samples/js/create_campaign.js b/Campaign_Samples/js/create_campaign.js index 3f79296..73eac94 100644 --- a/Campaign_Samples/js/create_campaign.js +++ b/Campaign_Samples/js/create_campaign.js @@ -3,21 +3,27 @@ var accountSid = ""; var apiKey = "" var apiToken = ""; var encoding = Buffer.from(apiKey + ':' + apiToken).toString('base64') -var options = { method: 'POST', - url: 'https://api.exotel.com/v2/accounts/'+ accountSid + '/campaigns', - headers: - { - Authorization: 'Basic ' + encoding, - 'Content-Type': 'application/json' }, - body: - { campaigns: - [ { caller_id: '0XXXXXXXXX1', - url: 'http://my.exotel.in/start/189810', - from: [ '+91XXXXXXXXX4', '+91XXXXXXXXX5' ], - schedule: { send_at: '2018-11-08T14:20:00+05:30' }, - status_callback: 'http:///1gvta9f1', - call_status_callback: 'http:///1gvta9f1' } ] }, - json: true }; +var options = { + method: 'POST', + url: 'https://api.exotel.com/v2/accounts/' + accountSid + '/campaigns', + headers: { + Authorization: 'Basic ' + encoding, + 'Content-Type': 'application/json' + }, + body: { + campaigns: [{ + caller_id: '0XXXXXXXXX1', + url: 'http://my.exotel.in/start/189810', + from: ['+91XXXXXXXXX4', '+91XXXXXXXXX5'], + schedule: { + send_at: '2018-11-08T14:20:00+05:30' + }, + status_callback: 'http:///1gvta9f1', + call_status_callback: 'http:///1gvta9f1' + }] + }, + json: true +}; request(options, function (error, response, body) { diff --git a/Campaign_Samples/js/delete_campaign_byID.js b/Campaign_Samples/js/delete_campaign_byID.js index 8539d16..1dcabce 100644 --- a/Campaign_Samples/js/delete_campaign_byID.js +++ b/Campaign_Samples/js/delete_campaign_byID.js @@ -4,16 +4,17 @@ var apiKey = "" var apiToken = ""; var encoding = Buffer.from(apiKey + ':' + apiToken).toString('base64') -var options = { method: 'DELETE', - url: 'https://api.exotel.com/v2/accounts/'+ accountSid +'/campaigns/', - headers: - { - Authorization: 'Basic ' + encoding - } }; +var options = { + method: 'DELETE', + url: 'https://api.exotel.com/v2/accounts/' + accountSid + '/campaigns/', + headers: { + Authorization: 'Basic ' + encoding + } +}; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); - + }); diff --git a/Campaign_Samples/js/edit_campaign.js b/Campaign_Samples/js/edit_campaign.js index cc1e4de..9506ace 100644 --- a/Campaign_Samples/js/edit_campaign.js +++ b/Campaign_Samples/js/edit_campaign.js @@ -4,22 +4,27 @@ var apiKey = "" var apiToken = ""; var encoding = Buffer.from(apiKey + ':' + apiToken).toString('base64') -var options = { method: 'PUT', - url: 'https://api.exotel.com/v2/accounts/'+ accountSid +'/campaigns/', - headers: - { - Authorization: 'Basic ' + encoding, - 'Content-Type': 'application/json' - }, - body: - { campaigns: - [ { caller_id: '0XXXXXXXXX1', - url: 'http://my.exotel.in/exoml/start/189810', - from: [ '+91XXXXXXXX4', '+91XXXXXXXXX5' ], - schedule: { send_at: '2018-11-09T10:00:00+05:30' }, - status_callback: 'http:///1gvta9f1', - call_status_callback: 'http:///1gvta9f1' } ] }, - json: true }; +var options = { + method: 'PUT', + url: 'https://api.exotel.com/v2/accounts/' + accountSid + '/campaigns/', + headers: { + Authorization: 'Basic ' + encoding, + 'Content-Type': 'application/json' + }, + body: { + campaigns: [{ + caller_id: '0XXXXXXXXX1', + url: 'http://my.exotel.in/exoml/start/189810', + from: ['+91XXXXXXXX4', '+91XXXXXXXXX5'], + schedule: { + send_at: '2018-11-09T10:00:00+05:30' + }, + status_callback: 'http:///1gvta9f1', + call_status_callback: 'http:///1gvta9f1' + }] + }, + json: true +}; request(options, function (error, response, body) { if (error) throw new Error(error); diff --git a/Campaign_Samples/js/get_campaign_byID.js b/Campaign_Samples/js/get_campaign_byID.js index 19fab1c..f2e3f84 100644 --- a/Campaign_Samples/js/get_campaign_byID.js +++ b/Campaign_Samples/js/get_campaign_byID.js @@ -4,12 +4,13 @@ var apiKey = "" var apiToken = ""; var encoding = Buffer.from(apiKey + ':' + apiToken).toString('base64'); -var options = { method: 'GET', - url: 'https://api.exotel.com/v2/accounts/'+ accountSid +'/campaigns/', - headers: - { - Authorization: 'Basic ' + encoding - } }; +var options = { + method: 'GET', + url: 'https://api.exotel.com/v2/accounts/' + accountSid + '/campaigns/', + headers: { + Authorization: 'Basic ' + encoding + } +}; request(options, function (error, response, body) { if (error) throw new Error(error); diff --git a/Campaign_Samples/python/bulk_get_campaigns.py b/Campaign_Samples/python/bulk_get_campaigns.py index f032a36..bf9faa6 100644 --- a/Campaign_Samples/python/bulk_get_campaigns.py +++ b/Campaign_Samples/python/bulk_get_campaigns.py @@ -1,19 +1,22 @@ -import requests, base64, json +import requests +import base64 +import json accountSid = "" apiKey = "" apiToken = "" encoding = base64.b64encode(apiKey + ":" + apiToken) -url = "https://api.exotel.com/v2/accounts/"+ accountSid +"/campaigns" +url = "https://api.exotel.com/v2/accounts/" + accountSid + "/campaigns" -querystring = {"page_size":"1","page":"1"} +querystring = {"page_size": "1", "page": "1"} payload = "" headers = { 'Content-Type': "application/json", 'Authorization': "Basic " + encoding - } +} -response = requests.request("GET", url, data=payload, headers=headers, params=querystring) +response = requests.request( + "GET", url, data=payload, headers=headers, params=querystring) print(response.text) diff --git a/Campaign_Samples/python/create_campaign.py b/Campaign_Samples/python/create_campaign.py index de801bf..9446f0f 100644 --- a/Campaign_Samples/python/create_campaign.py +++ b/Campaign_Samples/python/create_campaign.py @@ -1,4 +1,6 @@ -import requests, base64, json +import requests +import base64 +import json accountSid = "" apiKey = "" apiToken = "" @@ -6,19 +8,19 @@ url = "https://api.exotel.com/v2/accounts/"+accountSid+"/campaigns" -payload = json.dumps({ "campaigns": [{ - "caller_id": "0XXXXXXXXX1", - "url": "http://my.exotel.com/exoml/start_voice/208287", - "from": [ "+91XXXXXXXXX3", "+91XXXXXXXXX4" ], - "status_callback": "http:///1gvta9f1", - "call_status_callback": "http:///1gvta9f1"}] - }) +payload = json.dumps({"campaigns": [{ + "caller_id": "0XXXXXXXXX1", + "url": "http://my.exotel.com/exoml/start_voice/208287", + "from": ["+91XXXXXXXXX3", "+91XXXXXXXXX4"], + "status_callback": "http:///1gvta9f1", + "call_status_callback": "http:///1gvta9f1"}] +}) headers = { 'Content-Type': "application/json", 'Authorization': "Basic " + encoding - } +} response = requests.request("POST", url, data=payload, headers=headers) print(response.text) -print(json.dumps(json.loads(response.text), indent = 4, sort_keys = True)) +print(json.dumps(json.loads(response.text), indent=4, sort_keys=True)) diff --git a/Campaign_Samples/python/delete_campaigns_byID.py b/Campaign_Samples/python/delete_campaigns_byID.py index 95a7a54..0f3b65d 100644 --- a/Campaign_Samples/python/delete_campaigns_byID.py +++ b/Campaign_Samples/python/delete_campaigns_byID.py @@ -1,17 +1,20 @@ -import requests, base64, json +import requests +import base64 +import json accountSid = "" apiKey = "" apiToken = "" encoding = base64.b64encode(apiKey + ":" + apiToken) -url = "https://api.exotel.com/v2/accounts/"+ accountSid +"/campaigns/" +url = "https://api.exotel.com/v2/accounts/" + \ + accountSid + "/campaigns/" payload = "" headers = { 'Authorization': "Basic " + encoding - } +} response = requests.request("DELETE", url, data=payload, headers=headers) print(response.text) -print(json.dumps(json.loads(response.text), indent = 4, sort_keys = True)) +print(json.dumps(json.loads(response.text), indent=4, sort_keys=True)) diff --git a/Campaign_Samples/python/edit_campaigns.py b/Campaign_Samples/python/edit_campaigns.py index b1d6c26..8092463 100644 --- a/Campaign_Samples/python/edit_campaigns.py +++ b/Campaign_Samples/python/edit_campaigns.py @@ -1,24 +1,27 @@ -import requests, base64, json +import requests +import base64 +import json accountSid = "" apiKey = "" apiToken = "" encoding = base64.b64encode(apiKey + ":" + apiToken) -url = "https://api.exotel.com/v2/accounts/"+accountSid+"/campaigns/" +url = "https://api.exotel.com/v2/accounts/" + \ + accountSid+"/campaigns/" -payload = json.dumps({ "campaigns": [{ - "caller_id": "0XXXXXXXXX1", - "url": "http://my.exotel.com/exoml/start_voice/208287", - "from": [ "+91XXXXXXXXX4", "+91XXXXXXXXX5" ], - "status_callback": "http:///1gvta9f1", - "call_status_callback": "http:///1gvta9f1"}] - }) +payload = json.dumps({"campaigns": [{ + "caller_id": "0XXXXXXXXX1", + "url": "http://my.exotel.com/exoml/start_voice/208287", + "from": ["+91XXXXXXXXX4", "+91XXXXXXXXX5"], + "status_callback": "http:///1gvta9f1", + "call_status_callback": "http:///1gvta9f1"}] +}) headers = { 'Content-Type': "application/json", 'Authorization': "Basic " + encoding - } +} response = requests.request("PUT", url, data=payload, headers=headers) print(response.text) -print(json.dumps(json.loads(response.text), indent = 4, sort_keys = True)) +print(json.dumps(json.loads(response.text), indent=4, sort_keys=True)) diff --git a/Campaign_Samples/python/get_campaigns_byID.py b/Campaign_Samples/python/get_campaigns_byID.py index 3ca6619..929e147 100644 --- a/Campaign_Samples/python/get_campaigns_byID.py +++ b/Campaign_Samples/python/get_campaigns_byID.py @@ -1,17 +1,19 @@ -import requests, base64, json +import requests +import base64 +import json accountSid = "" accountToken = "" encoding = base64.b64encode(accountSid + ":" + accountToken) -url = "https://api.exotel.com/v2/accounts/"+accountSid+"/campaigns/" +url = "https://api.exotel.com/v2/accounts/" + \ + accountSid+"/campaigns/" payload = "" headers = { 'Authorization': "Basic " + encoding - } +} response = requests.request("GET", url, data=payload, headers=headers) print(response.text) -print(json.dumps(json.loads(response.text), indent = 4, sort_keys = True)) - +print(json.dumps(json.loads(response.text), indent=4, sort_keys=True)) diff --git a/README.md b/README.md index 791cc0b..09b0317 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ Exotel's Call and SMS API sample code + ======= + # ExotelSampleCode -The repository contains sample code for using the Exotel APIs. + +The repository contains sample code for using the Exotel APIs. To understand more about the APIs, please go the below link: https://developer.exotel.com/api/#intro @@ -10,29 +13,30 @@ https://developer.exotel.com/api/#intro To understand more about the Applets in Exotel, please go to the below link: https://developer.exotel.com/applet - # Example Programes: + ## are covered for the below languages - C# - Go - Java - Node.JS - PHP - Ruby - Python - + +- C# +- Go +- Java +- Node.JS +- PHP +- Ruby +- Python + # API Credentials - Replace and with the API key and token created by you. - Replace with your “Account sid” - Replace with the region of your account - of Singapore cluster is @api.exotel.com - of Mumbai cluster is @api.in.exotel.com - , and - are available in the API settings page of your Exotel Dashboard - - https://my.exotel.com/apisettings/site#api-credentials - - +- Replace `` and `` with the API key and token created by you. +- Replace `` with your "Account sid" +- Replace `` with the region of your account +- `` of Singapore cluster is `@api.exotel.com` +- `` of Mumbai cluster is `@api.in.exotel.com` + +`` , `` and `` are available in the API settings page of your Exotel Dashboard + +https://my.exotel.com/apisettings/site#api-credentials + # Read.me -Each of the subfolder have a separate Read.me for the details on the usage of the APIs. + +Each of the subfolder have a separate README for the details on the usage of the APIs. diff --git a/com/exotel/Connect/ExotelResponse.class b/com/exotel/Connect/ExotelResponse.class deleted file mode 100644 index 6b83a34..0000000 Binary files a/com/exotel/Connect/ExotelResponse.class and /dev/null differ diff --git a/com/exotel/Connect/ExotelStrings.class b/com/exotel/Connect/ExotelStrings.class deleted file mode 100644 index 283de19..0000000 Binary files a/com/exotel/Connect/ExotelStrings.class and /dev/null differ diff --git a/com/exotel/Connect/ExotelSuccessResponse.class b/com/exotel/Connect/ExotelSuccessResponse.class deleted file mode 100644 index 8dd6d9d..0000000 Binary files a/com/exotel/Connect/ExotelSuccessResponse.class and /dev/null differ diff --git a/java/ConnectCustomerToFlow.java b/java/ConnectCustomerToFlow.java index b723dab..ce7ff4e 100644 --- a/java/ConnectCustomerToFlow.java +++ b/java/ConnectCustomerToFlow.java @@ -1,10 +1,9 @@ - package com.exotel.Connect; public class ConnectCustomerToFlow { - public static void main(String[] args) { - ExotelCall calls = new ExotelCall(); - ExotelResponse res = calls.connectCustomerToFlow(); - - } + public static void main(String[] args) { + ExotelCall calls = new ExotelCall(); + ExotelResponse res = calls.connectCustomerToFlow(); + + } } diff --git a/java/ConnectToAgent.java b/java/ConnectToAgent.java index c831be5..f3846d3 100644 --- a/java/ConnectToAgent.java +++ b/java/ConnectToAgent.java @@ -10,16 +10,10 @@ import okhttp3.Response; import com.exotel.Connect.*; - public class ConnectToAgent { - public static void main(String[] args) { - ExotelAgent customer = new ExotelAgent(); - ExotelResponse res = customer.connectToAgent(); - - } -} - - - - + public static void main(String[] args) { + ExotelAgent customer = new ExotelAgent(); + ExotelResponse res = customer.connectToAgent(); + } +} diff --git a/java/ExotelAgent.java b/java/ExotelAgent.java index a955987..92b642a 100644 --- a/java/ExotelAgent.java +++ b/java/ExotelAgent.java @@ -14,51 +14,50 @@ import okhttp3.Response; class ExotelAgent { - public static String customerNumber = "your-customer-number"; - public static String url = "http://my.exotel.com/"; - public static String exotelSid = "your-exotel-Sid"; - public static String apiid = "your-API-Key"; - public static String apitoken = "your-API-token"; - public static String agentNumber = "your-agent-number"; - - public ExotelResponse connectToAgent() { - OkHttpClient client = new OkHttpClient().newBuilder().build(); - RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) - .addFormDataPart("From", customerNumber) - .addFormDataPart("To" , agentNumber ).build(); - - String credentials = Credentials.basic(apiid, apitoken); - - Request request = new Request.Builder() - .url(String.format(ExotelStrings.CONNECT_TO_AGENT_URL , exotelSid)).method("POST", body) - .addHeader("Authorization", credentials).addHeader("Content-Type", "application/json").build(); - - try { - Response response = client.newCall(request).execute(); - Gson connect = new Gson(); - String res = null; - try { - res = response.body().string(); - } catch (IOException e) { - e.printStackTrace(); - } - - ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); - - int status = response.code(); - - if (status == 200) { - ExotelSuccessResponse cust = new ExotelSuccessResponse(0); - return cust; - } else { - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } - } catch (Exception e) { - e.printStackTrace(); - } - - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } -} \ No newline at end of file + public static String customerNumber = "your-customer-number"; + public static String url = "http://my.exotel.com/"; + public static String exotelSid = "your-exotel-Sid"; + public static String apiid = "your-API-Key"; + public static String apitoken = "your-API-token"; + public static String agentNumber = "your-agent-number"; + + public ExotelResponse connectToAgent() { + OkHttpClient client = new OkHttpClient().newBuilder().build(); + RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("From", customerNumber) + .addFormDataPart("To", agentNumber).build(); + + String credentials = Credentials.basic(apiid, apitoken); + + Request request = new Request.Builder().url(String.format(ExotelStrings.CONNECT_TO_AGENT_URL, exotelSid)) + .method("POST", body).addHeader("Authorization", credentials).addHeader("Content-Type", "application/json") + .build(); + + try { + Response response = client.newCall(request).execute(); + Gson connect = new Gson(); + String res = null; + try { + res = response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + } + + ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); + + int status = response.code(); + + if (status == 200) { + ExotelSuccessResponse cust = new ExotelSuccessResponse(0); + return cust; + } else { + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } + } catch (Exception e) { + e.printStackTrace(); + } + + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } +} diff --git a/java/ExotelCall.java b/java/ExotelCall.java index 377f930..644ee34 100644 --- a/java/ExotelCall.java +++ b/java/ExotelCall.java @@ -14,51 +14,50 @@ import okhttp3.Response; class ExotelCall { - public static String customerNumber = "your-customer-number"; - public static String url = "http://my.exotel.com/"; - public static String accountSid = "your-exotel-account-sid"; - public static String flow_id = "your-flow-id"; - public static String authId = "your-API-Key"; - public static String authToken = "your-API-Token"; - - public ExotelResponse connectCustomerToFlow() { - OkHttpClient client = new OkHttpClient().newBuilder().build(); - RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) - .addFormDataPart("From", customerNumber) - .addFormDataPart("Url", url + accountSid + "/exoml/start_voice/" + flow_id).build(); - - String credentials = Credentials.basic(authId, authToken); - - Request request = new Request.Builder() - .url(String.format(ExotelStrings.CONNECT_CUSTOMER_TO_FLOW_URL, accountSid)).method("POST", body) - .addHeader("Authorization", credentials).addHeader("Content-Type", "application/json").build(); - - try { - Response response = client.newCall(request).execute(); - Gson connect = new Gson(); - String res = null; - try { - res = response.body().string(); - } catch (IOException e) { - e.printStackTrace(); - } - - ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); - - int status = response.code(); - - if (status == 200) { - ExotelSuccessResponse cust = new ExotelSuccessResponse(0); - return cust; - } else { - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } - } catch (Exception e) { - e.printStackTrace(); - } - - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } -} \ No newline at end of file + public static String customerNumber = "your-customer-number"; + public static String url = "http://my.exotel.com/"; + public static String accountSid = "your-exotel-account-sid"; + public static String flow_id = "your-flow-id"; + public static String authId = "your-API-Key"; + public static String authToken = "your-API-Token"; + + public ExotelResponse connectCustomerToFlow() { + OkHttpClient client = new OkHttpClient().newBuilder().build(); + RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("From", customerNumber) + .addFormDataPart("Url", url + accountSid + "/exoml/start_voice/" + flow_id).build(); + + String credentials = Credentials.basic(authId, authToken); + + Request request = new Request.Builder().url(String.format(ExotelStrings.CONNECT_CUSTOMER_TO_FLOW_URL, accountSid)) + .method("POST", body).addHeader("Authorization", credentials).addHeader("Content-Type", "application/json") + .build(); + + try { + Response response = client.newCall(request).execute(); + Gson connect = new Gson(); + String res = null; + try { + res = response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + } + + ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); + + int status = response.code(); + + if (status == 200) { + ExotelSuccessResponse cust = new ExotelSuccessResponse(0); + return cust; + } else { + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } + } catch (Exception e) { + e.printStackTrace(); + } + + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } +} diff --git a/java/ExotelFailureResponse.java b/java/ExotelFailureResponse.java index 4e2ce23..2f693cb 100644 --- a/java/ExotelFailureResponse.java +++ b/java/ExotelFailureResponse.java @@ -1,13 +1,13 @@ package com.exotel.Connect; class ExotelFailureResponse extends ExotelResponse { - public ExotelFailureResponse Calls; - public int httpStatus; - public String badrequest; - public String actionforbidden; - public String invalidfromspecified; + public ExotelFailureResponse Calls; + public int httpStatus; + public String badrequest; + public String actionforbidden; + public String invalidfromspecified; - public ExotelFailureResponse(int httpStatus) { - this.httpStatus = httpStatus; - } -} \ No newline at end of file + public ExotelFailureResponse(int httpStatus) { + this.httpStatus = httpStatus; + } +} diff --git a/java/ExotelResponse.java b/java/ExotelResponse.java index 70ebe26..71a41ac 100644 --- a/java/ExotelResponse.java +++ b/java/ExotelResponse.java @@ -1,6 +1,5 @@ package com.exotel.Connect; - public class ExotelResponse { - + } diff --git a/java/ExotelSend.java b/java/ExotelSend.java index e7c09d0..1b1ec63 100644 --- a/java/ExotelSend.java +++ b/java/ExotelSend.java @@ -15,60 +15,56 @@ import okhttp3.Response; enum SmsType { - TRANSACTIONAL, PROMOTIONAL; + TRANSACTIONAL, PROMOTIONAL; } class ExotelSend { - public static String customerNumber = "your-customer-number"; - public static String agentNumber = "your-agent-number"; - public static String url = "http://my.exotel.com/"; - public static String exotelSid = "your-exotel-sid"; - public static String apiid = "your-API-Key"; - public static String apitoken = "your-API-token"; - public static String msg = "your-message"; + public static String customerNumber = "your-customer-number"; + public static String agentNumber = "your-agent-number"; + public static String url = "http://my.exotel.com/"; + public static String exotelSid = "your-exotel-sid"; + public static String apiid = "your-API-Key"; + public static String apitoken = "your-API-token"; + public static String msg = "your-message"; + public ExotelResponse SendUnicode() { + OkHttpClient client = new OkHttpClient().newBuilder().build(); + RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("From", customerNumber) + .addFormDataPart("To", agentNumber).addFormDataPart("SmsType", toString()) + .addFormDataPart("EncodingType", "plain").addFormDataPart("Body", body); - public ExotelResponse SendUnicode() { - OkHttpClient client = new OkHttpClient().newBuilder().build(); - RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) - .addFormDataPart("From", customerNumber) - .addFormDataPart("To",agentNumber ) - .addFormDataPart("SmsType", toString()) - .addFormDataPart("EncodingType", "plain") - .addFormDataPart("Body",body); + String credentials = Credentials.basic(apiid, apitoken); - String credentials = Credentials.basic(apiid, apitoken); + Request request = new Request.Builder().url(String.format(ExotelStrings.SEND_UNICODE_URL, exotelSid)) + .method("POST", body).addHeader("Authorization", credentials).addHeader("Content-Type", "application/json") + .build(); - Request request = new Request.Builder() - .url(String.format(ExotelStrings.SEND_UNICODE_URL, exotelSid)).method("POST", body) - .addHeader("Authorization", credentials).addHeader("Content-Type", "application/json").build(); + try { + Response response = client.newCall(request).execute(); + Gson connect = new Gson(); + String res = null; + try { + res = response.body().string(); + } catch (IOException error) { + error.printStackTrace(); + } - try { - Response response = client.newCall(request).execute(); - Gson connect = new Gson(); - String res = null; - try { - res = response.body().string(); - } catch (IOException error) { - error.printStackTrace(); - } + ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); - ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); + int status = response.code(); - int status = response.code(); + if (status == 200) { + ExotelSuccessResponse cust = new ExotelSuccessResponse(0); + return cust; + } else { + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } + } catch (Exception error) { + error.printStackTrace(); + } - if (status == 200) { - ExotelSuccessResponse cust = new ExotelSuccessResponse(0); - return cust; - } else { - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } - } catch (Exception error) { - error.printStackTrace(); - } - - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } -} \ No newline at end of file + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } +} diff --git a/java/ExotelStrings.java b/java/ExotelStrings.java index 284ae98..29c2f59 100644 --- a/java/ExotelStrings.java +++ b/java/ExotelStrings.java @@ -1,9 +1,7 @@ package com.exotel.Connect; -public interface ExotelStrings { - String CONNECT_TO_AGENT_URL = "https://api.exotel.com/v1/Accounts/%s/Calls/connect.json"; - String CONNECT_CUSTOMER_TO_FLOW_URL = "https://api.exotel.com/v1/Accounts/%s/Calls/connect.json"; - String SEND_UNICODE_URL = "https://api.exotel.com/v1/Accounts/%s/Sms/send.json"; +public interface ExotelStrings { + String CONNECT_TO_AGENT_URL = "https://api.exotel.com/v1/Accounts/%s/Calls/connect.json"; + String CONNECT_CUSTOMER_TO_FLOW_URL = "https://api.exotel.com/v1/Accounts/%s/Calls/connect.json"; + String SEND_UNICODE_URL = "https://api.exotel.com/v1/Accounts/%s/Sms/send.json"; } - - diff --git a/java/ExotelSuccessResponse.java b/java/ExotelSuccessResponse.java index 5c62010..fdbca56 100644 --- a/java/ExotelSuccessResponse.java +++ b/java/ExotelSuccessResponse.java @@ -1,13 +1,13 @@ package com.exotel.Connect; +public class ExotelSuccessResponse extends ExotelResponse { + public ExotelSuccessResponse Call; + public String Sid; + public String AccountSid; + public String To; + public String From; + public String Status; -public class ExotelSuccessResponse extends ExotelResponse{ - public ExotelSuccessResponse Call; - public String Sid; - public String AccountSid; - public String To; - public String From; - public String Status; - public ExotelSuccessResponse(int httpStatus) { - } + public ExotelSuccessResponse(int httpStatus) { } +} diff --git a/java/README.md b/java/README.md index e994bb5..9e03286 100644 --- a/java/README.md +++ b/java/README.md @@ -1,138 +1,143 @@ -EXOTEL-JAVA +# EXOTEL-JAVA + +## DOCUMENTATION -# DOCUMENTATION The documentation for the Exotel API can be found here https://developer.exotel.com/api/#intro. -# SUPPORTED NODEJS VERSIONS +## SUPPORTED JAVA VERSIONS + This library supports the following Java implementations: - Java 8 - openjdk 8 - -# INSTALLATION - 1 First, update the apt package index with: - $sudo apt update - - 2 Once the package index is updated install the default Java OpenJDK package with: - $ sudo apt install default-jdk - - 3 Verify the installation, by running the following command which will print the Java version: - java -version - -# Getting Started -Setup Work -## Put Your Own Credentials Here +- Java 8 +- openjdk 8 + +## INSTALLATION + +1. First, update the apt package index with: + + sudo apt update + +2. Once the package index is updated install the default Java OpenJDK package with: + + sudo apt install default-jdk + +3. Verify the installation, by running the following command which will print the Java version: + + java -version + +## Getting Started + +### Setup Work + +Put Your Own Credentials Here + Exotel_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' API_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy' -# Make a Call +### Make a Call + ```java class ExotelCall { - public static String customerNumber = "your-customer-number"; - public static String url = "http://my.exotel.com/"; - public static String exotelsid = "your-exotel-sid"; - public static String flow_id = "your-flow-id"; - public static String apiid = "your-API-Key"; - public static String apitoken = "your-API-token"; - - public ExotelResponse connectCustomerToFlow() { - OkHttpClient client = new OkHttpClient().newBuilder().build(); - RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) - .addFormDataPart("From", customerNumber) - .addFormDataPart("Url", url + exotelsid + "/exoml/start_voice/" + flow_id).build(); - - String credentials = Credentials.basic(apiid, apitoken); - - Request request = new Request.Builder() - .url(String.format(ExotelStrings.CONNECT_CUSTOMER_TO_FLOW_URL, exotelsid)).method("POST", body) - .addHeader("Authorization", credentials).addHeader("Content-Type", "application/json").build(); - - try { - Response response = client.newCall(request).execute(); - Gson connect = new Gson(); - String res = null; - try { - res = response.body().string(); - } catch (IOException e) { - e.printStackTrace(); - } - - ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); - - int status = response.code(); - - if (status == 200) { - ExotelSuccessResponse cust = new ExotelSuccessResponse(0); - return cust; - } else { - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } - } catch (Exception e) { - e.printStackTrace(); - } - - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } + public static String customerNumber = "your-customer-number"; + public static String url = "http://my.exotel.com/"; + public static String exotelsid = "your-exotel-sid"; + public static String flow_id = "your-flow-id"; + public static String apiid = "your-API-Key"; + public static String apitoken = "your-API-token"; + + public ExotelResponse connectCustomerToFlow() { + OkHttpClient client = new OkHttpClient().newBuilder().build(); + RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("From", customerNumber) + .addFormDataPart("Url", url + exotelsid + "/exoml/start_voice/" + flow_id).build(); + + String credentials = Credentials.basic(apiid, apitoken); + + Request request = new Request.Builder().url(String.format(ExotelStrings.CONNECT_CUSTOMER_TO_FLOW_URL, exotelsid)) + .method("POST", body).addHeader("Authorization", credentials).addHeader("Content-Type", "application/json") + .build(); + + try { + Response response = client.newCall(request).execute(); + Gson connect = new Gson(); + String res = null; + try { + res = response.body().string(); + } catch (IOException e) { + e.printStackTrace(); + } + + ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); + + int status = response.code(); + + if (status == 200) { + ExotelSuccessResponse cust = new ExotelSuccessResponse(0); + return cust; + } else { + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } + } catch (Exception e) { + e.printStackTrace(); + } + + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } } - ``` -# Send an SMS + +### Send an SMS + ```java class ExotelSend { - public static String customerNumber = "your-customer-number"; - public static String agentNumber = "your-agent-number"; - public static String url = "http://my.exotel.com/"; - public static String exotelSid = "your-exotelsid"; - public static String apiid = "your-API-Key"; - public static String apitoken = "your-API-token"; - public static String msg = "your-message"; - - - public ExotelResponse SendUnicode() { - OkHttpClient client = new OkHttpClient().newBuilder().build(); - RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) - .addFormDataPart("From", customerNumber) - .addFormDataPart("To",agentNumber ) - .addFormDataPart("SmsType", toString()) - .addFormDataPart("EncodingType", "plain") - .addFormDataPart("Body",body); - - String credentials = Credentials.basic(apiid, apitoken); - - Request request = new Request.Builder() - .url(String.format(ExotelStrings.SEND_UNICODE_URL, exotelSid)).method("POST", body) - .addHeader("Authorization", credentials).addHeader("Content-Type", "application/json").build(); - - try { - Response response = client.newCall(request).execute(); - Gson connect = new Gson(); - String res = null; - try { - res = response.body().string(); - } catch (IOException error) { - error.printStackTrace(); - } - - ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); - - int status = response.code(); - - if (status == 200) { - ExotelSuccessResponse cust = new ExotelSuccessResponse(0); - return cust; - } else { - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } - } catch (Exception error) { - error.printStackTrace(); - } - - ExotelFailureResponse cust = new ExotelFailureResponse(0); - return cust; - } + public static String customerNumber = "your-customer-number"; + public static String agentNumber = "your-agent-number"; + public static String url = "http://my.exotel.com/"; + public static String exotelSid = "your-exotelsid"; + public static String apiid = "your-API-Key"; + public static String apitoken = "your-API-token"; + public static String msg = "your-message"; + + public ExotelResponse SendUnicode() { + OkHttpClient client = new OkHttpClient().newBuilder().build(); + RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("From", customerNumber) + .addFormDataPart("To", agentNumber).addFormDataPart("SmsType", toString()) + .addFormDataPart("EncodingType", "plain").addFormDataPart("Body", body); + + String credentials = Credentials.basic(apiid, apitoken); + + Request request = new Request.Builder().url(String.format(ExotelStrings.SEND_UNICODE_URL, exotelSid)) + .method("POST", body).addHeader("Authorization", credentials).addHeader("Content-Type", "application/json") + .build(); + + try { + Response response = client.newCall(request).execute(); + Gson connect = new Gson(); + String res = null; + try { + res = response.body().string(); + } catch (IOException error) { + error.printStackTrace(); + } + + ExotelResponse SuccessResponse = connect.fromJson(res, ExotelResponse.class); + + int status = response.code(); + + if (status == 200) { + ExotelSuccessResponse cust = new ExotelSuccessResponse(0); + return cust; + } else { + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } + } catch (Exception error) { + error.printStackTrace(); + } + + ExotelFailureResponse cust = new ExotelFailureResponse(0); + return cust; + } } - ``` diff --git a/java/SendUnicode.java b/java/SendUnicode.java index 27ef267..e980826 100644 --- a/java/SendUnicode.java +++ b/java/SendUnicode.java @@ -1,4 +1,3 @@ - package com.exotel.Connect; import okhttp3.Credentials; @@ -13,16 +12,8 @@ import com.google.gson.Gson; public class SendUnicode { - public static void main(String[] args) { - ExotelSend send = new ExotelSend(); - ExotelResponse res = send.SendUnicode(); - - // use res - //sSystem.out.println("hi"); - } + public static void main(String[] args) { + ExotelSend send = new ExotelSend(); + ExotelResponse res = send.SendUnicode(); + } } - - - - - diff --git a/nodejs/ReadMe.md b/nodejs/ReadMe.md index bd48260..3172119 100644 --- a/nodejs/ReadMe.md +++ b/nodejs/ReadMe.md @@ -1,135 +1,147 @@ -EXOTEL-NODEJS +# EXOTEL-NODEJS +## DOCUMENTATION -# DOCUMENTATION The documentation for the Exotel API can be found here https://developer.exotel.com/api/#intro. +## SUPPORTED NODEJS VERSIONS -# SUPPORTED NODEJS VERSIONS This library supports the following Nodejs implementations: - - Nodejs v8 - -# INSTALLATION - To get this version, you can use the apt package manager. Refresh your local package index by typing: - $ sudo apt update - Install Node.js from the repositories: - $ sudo apt install nodejs - If the package in the repositories suits your needs, this is all you need to do to get set up with Node.js. In most cases, you’ll also want to also install npm, the Node.js package manager. You can do this by typing: - $ sudo apt install npm - This will allow you to install modules and packages to use with Node.js. - Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node. Keep this in mind as you are running software. - - To check which version of Node.js you have installed after these initial steps, type: - + +- Nodejs v8 + +## INSTALLATION + +To get this version, you can use the apt package manager. Refresh your local package index by typing: + + sudo apt update + +Install Node.js from the repositories: + + sudo apt install nodejs + +If the package in the repositories suits your needs, this is all you need to do to get set up with Node.js. In most cases, you’ll also want to also install npm, the Node.js package manager. You can do this by typing: + + sudo apt install npm + +This will allow you to install modules and packages to use with Node.js. +Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node. Keep this in mind as you are running software. + +To check which version of Node.js you have installed after these initial steps, type: + nodejs -v -# Getting Started -Setup Work -## Put Your Own Credentials here +## Getting Started + +## Setup + +Put Your Own Credentials here + Exotel_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' API_Token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy' -# Make a Call +## Make a Call - ```javascript - key="xxxxxxxx" - sid="xxxxxxxx" - token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - from="xxxxxxxxxxx" - to="xxxxxxxxxxxx" +```javascript +key="xxxxxxxx" +sid="xxxxxxxx" +token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +from="xxxxxxxxxxx" +to="xxxxxxxxxxxx" ``` ```javascript -const formUrlEncoded = x =>Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') +const formUrlEncoded = x => Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') const axios = require('axios') -url="https://"+key+":"+token+"@api.exotel.in/v1/Accounts/"+sid+"/Calls/connect" -axios.post(url, - formUrlEncoded({ - "From": from, - "To": to, - "CallerId":'xxxxxxxxx', - "CallerType": 'promo', -}), -{ - withCredentials: true, - headers: { - "Accept":"application/x-www-form-urlencoded", - "Content-Type": "application/x-www-form-urlencoded" - } - }, - ) -.then((res) => { - console.log(`statusCode: ${res.statusCode}`) - console.log(res) -}) -.catch((error) => { - console.error(error) -}) +url = "https://" + key + ":" + token + "@api.exotel.in/v1/Accounts/" + sid + "/Calls/connect" +axios.post(url, + formUrlEncoded({ + "From": from, + "To": to, + "CallerId": 'xxxxxxxxx', + "CallerType": 'promo', + }), { + withCredentials: true, + headers: { + "Accept": "application/x-www-form-urlencoded", + "Content-Type": "application/x-www-form-urlencoded" + } + }, + ) + .then((res) => { + console.log(`statusCode: ${res.statusCode}`) + console.log(res) + }) + .catch((error) => { + console.error(error) + }) ``` -# Send an SMS +## Send an SMS + ```javascript -key="xxxxxxx" -sid="xxxxxxx" -token="xxxxxxxxxxxxxxxxxxxxx" -from="xxxxxxxxx" -to="xxxxxxxxxxx" -body="Good Evening" +key = "xxxxxxx" +sid = "xxxxxxx" +token = "xxxxxxxxxxxxxxxxxxxxx" +from = "xxxxxxxxx" +to = "xxxxxxxxxxx" +body = "Good Evening" -const formUrlEncoded = x =>Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') +const formUrlEncoded = x => Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') const axios = require('axios') -url="https://"+key+":"+token+"@api.exotel.in/v1/Accounts/"+sid+"/Sms/send.json" -axios.post(url, - formUrlEncoded({ - "From": from, - "To": to, - "Body":body -}), -{ - withCredentials: true, - headers: { - "Accept":"application/x-www-form-urlencoded", - "Content-Type": "application/x-www-form-urlencoded" - } - }, - ) -.then((res) => { - console.log(`statusCode: ${res.statusCode}`) - console.log(res) -}) -.catch((error) => { - console.error(error) -}) - +url = "https://" + key + ":" + token + "@api.exotel.in/v1/Accounts/" + sid + "/Sms/send.json" +axios.post(url, + formUrlEncoded({ + "From": from, + "To": to, + "Body": body + }), { + withCredentials: true, + headers: { + "Accept": "application/x-www-form-urlencoded", + "Content-Type": "application/x-www-form-urlencoded" + } + }, + ) + .then((res) => { + console.log(`statusCode: ${res.statusCode}`) + console.log(res) + }) + .catch((error) => { + console.error(error) + }) ``` -# RESULT -HTTO Response Code: 200 - ```xml - \n - \n \n - xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n - \n - 2020-02-24 13:21:32\n - 2020-02-24 13:21:32\n - xxxxxxx\n - +xxxxxxxxxx\n - +xxxxxxxxxx\n - +xxxxxxxxxxx\n - in-progress\n - 2020-02-24 13:21:32\n - \n \n \n - outbound-api\n - \n - \n - \n - /v1/Accounts/xxxxxx/Calls/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n - \n - \n - /v1/Accounts/xxxxxxx/Calls/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Legs\n \n \n\n' +## RESULT + +HTTP Response Code: 200 +```xml + + + + xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + 2020-02-24 13:21:32 + 2020-02-24 13:21:32 + xxxxxxx + +xxxxxxxxxx + +xxxxxxxxxx + +xxxxxxxxxxx + in-progress + 2020-02-24 13:21:32 + + + + outbound-api + + + + /v1/Accounts/xxxxxx/Calls/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + + /v1/Accounts/xxxxxxx/Calls/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Legs + + + ``` - - - diff --git a/nodejs/connecttoagent.js b/nodejs/connecttoagent.js index c57b42e..421333b 100644 --- a/nodejs/connecttoagent.js +++ b/nodejs/connecttoagent.js @@ -1,34 +1,33 @@ -key="API Key" -sid="Exotel Sid" -token="API Token" -from="xxxxxxxxxxx" -to="xxxxxxxxxxxx" +key = "API Key" +sid = "Exotel Sid" +token = "API Token" +from = "xxxxxxxxxxx" +to = "xxxxxxxxxxxx" -const formUrlEncoded = x =>Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') +const formUrlEncoded = x => Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') const axios = require('axios') -url="https://"+key+":"+token+"@api.exotel.in/v1/Accounts/"+sid+"/Calls/connect" -axios.post(url, - formUrlEncoded({ - "From": from, - "To": to, - "CallerId":'xxxxxxxxx', - "CallerType": 'promo', +url = "https://" + key + ":" + token + "@api.exotel.in/v1/Accounts/" + sid + "/Calls/connect" +axios.post(url, + formUrlEncoded({ + "From": from, + "To": to, + "CallerId": 'xxxxxxxxx', + "CallerType": 'promo', -}), -{ - withCredentials: true, - headers: { - "Accept":"application/x-www-form-urlencoded", + }), { + withCredentials: true, + headers: { + "Accept": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded" - } - }, + } + }, ) -.then((res) => { - console.log(`statusCode: ${res.statusCode}`) - console.log(res) -}) -.catch((error) => { - console.error(error) -}) \ No newline at end of file + .then((res) => { + console.log(`statusCode: ${res.statusCode}`) + console.log(res) + }) + .catch((error) => { + console.error(error) + }) diff --git a/nodejs/connecttoflow.js b/nodejs/connecttoflow.js index 78e07d6..384970a 100644 --- a/nodejs/connecttoflow.js +++ b/nodejs/connecttoflow.js @@ -1,36 +1,35 @@ -key="API Key" -sid="Exotel Sid" -token="API Token" -from="xxxxxxxxxxxxxx" -to="xxxxxxxxxx" +key = "API Key" +sid = "Exotel Sid" +token = "API Token" +from = "xxxxxxxxxxxxxx" +to = "xxxxxxxxxx" -const r = x =>Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') +const r = x => Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') const axios = require('axios') -url="https://"+key+":"+token+"@api.exotel.in/v1/Accounts/"+sid+"/Calls/connect.json" -axios.post(url, - r({ - "From": from, - "To": to, - "CallerId":'xxxxxxxxx', - "CallerType": 'trans', - "Url" :'http://my.exotel.com/Exotel/exoml/start_voice/26555', +url = "https://" + key + ":" + token + "@api.exotel.in/v1/Accounts/" + sid + "/Calls/connect.json" +axios.post(url, + r({ + "From": from, + "To": to, + "CallerId": 'xxxxxxxxx', + "CallerType": 'trans', + "Url": 'http://my.exotel.com/Exotel/exoml/start_voice/26555', -}), -{ - withCredentials: true, - headers: { - "Accept":"application/x-www-form-urlencoded", + }), { + withCredentials: true, + headers: { + "Accept": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded" - } - }, + } + }, ) -.then((res) => { - console.log(`statusCode: ${res.statusCode}`) - console.log(res) -}) -.catch((error) => { - console.error(error) -}) \ No newline at end of file + .then((res) => { + console.log(`statusCode: ${res.statusCode}`) + console.log(res) + }) + .catch((error) => { + console.error(error) + }) diff --git a/nodejs/send.js b/nodejs/send.js index 37b6a33..dc63cfb 100644 --- a/nodejs/send.js +++ b/nodejs/send.js @@ -1,32 +1,31 @@ -key="API Key" -sid="Exotel Sid" -token="API Token" -from="xxxxxxxxx" -to="xxxxxxxxxxx" -body="Good Evening" +key = "API Key" +sid = "Exotel Sid" +token = "API Token" +from = "xxxxxxxxx" +to = "xxxxxxxxxxx" +body = "Good Evening" -const formUrlEncoded = x =>Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') +const formUrlEncoded = x => Object.keys(x).reduce((p, c) => p + `&${c}=${encodeURIComponent(x[c])}`, '') const axios = require('axios') -url="https://"+key+":"+token+"@api.exotel.in/v1/Accounts/"+sid+"/Sms/send.json" -axios.post(url, - formUrlEncoded({ - "From": from, - "To": to, - "Body":body -}), -{ - withCredentials: true, - headers: { - "Accept":"application/x-www-form-urlencoded", +url = "https://" + key + ":" + token + "@api.exotel.in/v1/Accounts/" + sid + "/Sms/send.json" +axios.post(url, + formUrlEncoded({ + "From": from, + "To": to, + "Body": body + }), { + withCredentials: true, + headers: { + "Accept": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded" - } - }, + } + }, ) -.then((res) => { - console.log(`statusCode: ${res.statusCode}`) - console.log(res) -}) -.catch((error) => { - console.error(error) -}) \ No newline at end of file + .then((res) => { + console.log(`statusCode: ${res.statusCode}`) + console.log(res) + }) + .catch((error) => { + console.error(error) + }) diff --git a/php/README.md b/php/README.md index 524814c..4c17a7d 100644 --- a/php/README.md +++ b/php/README.md @@ -3,7 +3,7 @@ The documentation for the Exotel API can be found link:https://developer.exotel.com/api/#intro # SUPPORTED PHP VERSIONS -This library supports the following Python implementations: +This library supports the following PHP implementations: PHP 7.2 PHP 7.3 diff --git a/python/ReadMe.md b/python/ReadMe.md index 0795d00..e6147d8 100644 --- a/python/ReadMe.md +++ b/python/ReadMe.md @@ -1,146 +1,164 @@ # EXOTEL-PYTHON SAMPLE CODE -# DOCUMENTATION +## DOCUMENTATION + The documentation for the Exotel API can be found in the below link: https://developer.exotel.com/api/#intro -# SUPPORTED PYTHON VERSION +## SUPPORTED PYTHON VERSION + This library supports the following Python implementations: +- Python 2.7 +- Python 3.4 +- Python 3.5 +- Python 3.6 +- Python 3.7 +- Python 3.8 - Python 2.7 - Python 3.4 - Python 3.5 - Python 3.6 - Python 3.7 - Python 3.8 +## INSTALLATION -# INSTALLATION To install Python latest stable version: -01 Start by updating the packages list and installing the prerequisites: - $ sudo apt update - $ sudo apt install software-properties-common +1. Start by updating the packages list and installing the prerequisites: + + sudo apt update + sudo apt install software-properties-common + +2. Next, add the deadsnakes PPA to your sources list: + + sudo add-apt-repository ppa:deadsnakes/ppa + + When prompted press Enter to continue: + Press [ENTER] to continue or Ctrl + C to cancel adding it. + +3. Once the repository is enabled, install Python 3.7 with: + + sudo apt install python3.7 -02 Next, add the deadsnakes PPA to your sources list: - $ sudo add-apt-repository ppa:deadsnakes/ppa -When prompted press Enter to continue: -Press [ENTER] to continue or Ctrl-c to cancel adding it. +4. At this point, Python 3.7 is installed on your Ubuntu system and ready to be used. You can verify it by typing: -03 Once the repository is enabled, install Python 3.7 with: - $sudo apt install python3.7 + $ python3.7 --version + Python 3.7.3 -04 At this point, Python 3.7 is installed on your Ubuntu system and ready to be used. You can verify it by typing: - $python3.7 --version - Python 3.7.3 +## GETTING STARTED + +### Settings for Exotel API + +Get your SID and token from -# GETTING STARTED -# Settings for Exotel API -## Get your SID and token from https://my.exotel.com/apisettings/site#api-credentials - sid = 'XXXXXX' - key = 'XXXXXX' - token = 'XXXXXXXXXXXXXXXXXXXXXXXXX' + sid = 'XXXXXX' + key = 'XXXXXX' + token = 'XXXXXXXXXXXXXXXXXXXXXXXXX' smsurl = 'https://api.exotel.in/v1/Accounts//Sms/send.json' callurl = 'https://api.exotel.in/v1/Accounts//Calls/connect.json' from_no = 'XXXXXXXXXXX' to = 'XXXXXXXXXXX' - url = "http://my.exotel.com//exoml/start_voice/", - -# MAKE A CALL + url = "http://my.exotel.com//exoml/start_voice/" +### MAKE A CALL ```python import requests -from pprint import pprint - -from settings import sid, token, callurl,from_no,to +from pprint +import pprint +from settings +import sid, token, callurl, from_no, to def connect_customer_to_agent( - sid, - token, - agent_no, - customer_no, - callerid, - timelimit=None, - timeout=None, - calltype = 'trans' - ): - return requests.post( - callurl, - auth = (sid, token), - data = { - 'From': from_no, - 'To' : to, - - } - ) + sid, + token, + agent_no, + customer_no, + callerid, + timelimit = None, + timeout = None, + calltype = 'trans' + ): + return requests.post( + callurl, + auth = (sid, token), + data = { + 'From': from_no, + 'To': to, + + } + ) if __name__ == '__main__': - r = connect_customer_to_agent( - sid, - token, - agent_no = "your-agent-number", - customer_no = "your-customer-number", - callerid = "", - timelimit = "", - timeout = "", - calltype = "trans" - ) - print (r.status_code) - pprint(r.json()) + r = connect_customer_to_agent( + sid, + token, + agent_no = "your-agent-number", + customer_no = "your-customer-number", + callerid = "", + timelimit = "", + timeout = "", + calltype = "trans" + ) +print(r.status_code) +pprint(r.json()) ``` - -# SEND AN SMS + +### SEND AN SMS + ```python import requests -from pprint import pprint +from pprint +import pprint -from settings import sid, token, smsurl,from_no,to +from settings +import sid, token, smsurl, from_no, to -def send_message (sid,token, sms_from, sms_to, sms_body) : - return requests.post( - smsurl, - auth = (sid, token), - data = { - 'From' : from_no, - 'To' : to, - 'Body' : "your-message" - } - ) +def send_message(sid, token, sms_from, sms_to, sms_body): + return requests.post( + smsurl, + auth = (sid, token), + data = { + 'From': from_no, + 'To': to, + 'Body': "your-message" + } + ) if __name__ == '__main__': - r = send_message( - sid, - token, - sms_from = 'your-agent-number', - sms_to = 'your-customer-number', - sms_body = 'your-message' - ) - print (r.status_code) - pprint(r.json()) - + r = send_message( + sid, + token, + sms_from = 'your-agent-number', + sms_to = 'your-customer-number', + sms_body = 'your-message' + ) +print(r.status_code) +pprint(r.json()) ``` -# Result -HTTO Response : 200 - - `{'SMSMessage': {'AccountSid': 'Exotel', - 'ApiVersion': None, - 'Body': 'hii', - 'DateCreated': '2020-02-20 15:54:42', - 'DateSent': None, - 'DateUpdated': '2020-02-20 15:54:42', - 'DetailedStatus': 'PENDING_TO_OPERATOR', - 'DetailedStatusCode': 21010, - 'Direction': 'outbound-api', - 'From': 'xxxxxxxxx/EXOTEL', - 'Price': None, - 'Sid': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - 'Status': 'queued', - 'To': '+xxxxxxxxxxxxx', - 'Uri': '/v1/Accounts/Exotel/SMS/Messages/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.json'}}` - +### Result + +HTTP Response : 200 + +```json +{ + "SMSMessage": { + "AccountSid": "Exotel", + "ApiVersion": null, + "Body": "hii", + "DateCreated": "2020-02-20 15:54:42", + "DateSent": null, + "DateUpdated": "2020-02-20 15:54:42", + "DetailedStatus": "PENDING_TO_OPERATOR", + "DetailedStatusCode": 21010, + "Direction": "outbound-api", + "From": "xxxxxxxxx/EXOTEL", + "Price": null, + "Sid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "Status": "queued", + "To": "+xxxxxxxxxxxxx", + "Uri": "/v1/Accounts/Exotel/SMS/Messages/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.json" + } +} +``` diff --git a/python/connecttoagent.py b/python/connecttoagent.py index cd35eb9..17e89bf 100644 --- a/python/connecttoagent.py +++ b/python/connecttoagent.py @@ -2,39 +2,40 @@ from pprint import pprint -from settings import sid, token, callurl,from_no,to +from settings import sid, token, callurl, from_no, to def connect_customer_to_agent( - sid, - token, - agent_no, - customer_no, - callerid, - timelimit=None, - timeout=None, - calltype = 'trans' - ): + sid, + token, + agent_no, + customer_no, + callerid, + timelimit=None, + timeout=None, + calltype='trans' +): return requests.post( callurl, - auth = (sid, token), - data = { + auth=(sid, token), + data={ 'From': from_no, - 'To' : to, - + 'To': to, + } ) + if __name__ == '__main__': r = connect_customer_to_agent( sid, token, - agent_no = "your-agent-number", - customer_no = "your-customer-number", - callerid = "", - timelimit = "", - timeout = "", - calltype = "trans" + agent_no="your-agent-number", + customer_no="your-customer-number", + callerid="", + timelimit="", + timeout="", + calltype="trans" ) - print (r.status_code) + print(r.status_code) pprint(r.json()) diff --git a/python/connecttoflow.py b/python/connecttoflow.py index ffd6c6f..d83aa05 100644 --- a/python/connecttoflow.py +++ b/python/connecttoflow.py @@ -6,21 +6,21 @@ def connect_customer( - sid, - token, - customer_no, - agent_no, - url, - timelimit=None, - timeout=None, - calltype="trans", - ): + sid, + token, + customer_no, + agent_no, + url, + timelimit=None, + timeout=None, + calltype="trans", +): return requests.post( callurl, auth=(sid, token), data={ 'From': from_no, - 'To' : to, + 'To': to, } ) @@ -29,12 +29,12 @@ def connect_customer( r = connect_customer( sid, token, - customer_no = "your-customer-number", - agent_no = "your-agent-number", - url = "http://my.exotel.in/exoml/start/", - timelimit = "", - timeout = "", - calltype = "trans", - ) - print (r.status_code) + customer_no="your-customer-number", + agent_no="your-agent-number", + url="http://my.exotel.in/exoml/start/", + timelimit="", + timeout="", + calltype="trans", + ) + print(r.status_code) pprint(r.json()) diff --git a/python/sendsms.py b/python/sendsms.py index be73f5e..cc9bd5c 100644 --- a/python/sendsms.py +++ b/python/sendsms.py @@ -2,26 +2,28 @@ from pprint import pprint -from settings import sid, token, smsurl,from_no,to +from settings import sid, token, smsurl, from_no, to -def send_message (sid,token, sms_from, sms_to, sms_body) : + +def send_message(sid, token, sms_from, sms_to, sms_body): return requests.post( smsurl, - auth = (sid, token), - data = { - 'From' : from_no, - 'To' : to, - 'Body' : "your-message" + auth=(sid, token), + data={ + 'From': from_no, + 'To': to, + 'Body': "your-message" } ) + if __name__ == '__main__': r = send_message( sid, token, - sms_from = 'your-agent-number', - sms_to = 'your-customer-number', - sms_body = 'your-message' + sms_from='your-agent-number', + sms_to='your-customer-number', + sms_body='your-message' ) - print (r.status_code) + print(r.status_code) pprint(r.json()) diff --git a/python/settings.py b/python/settings.py index f926e4d..3a0f085 100644 --- a/python/settings.py +++ b/python/settings.py @@ -10,11 +10,11 @@ to - customer number (the person to whom the call is made) ''' -sid = ' Exotel Sid' -key = 'API Key' -token = 'API Token' -smsurl = 'https://api.exotel.in/v1/Accounts//Sms/send.json' -callurl = 'https://api.exotel.in/v1/Accounts//Calls/connect.json' -from_no = 'XXXXXXXXXXX' -to = 'XXXXXXXXXXX' -url = "http://my.exotel.com//exoml/start_voice/", \ No newline at end of file +sid = ' Exotel Sid' +key = 'API Key' +token = 'API Token' +smsurl = 'https://api.exotel.in/v1/Accounts//Sms/send.json' +callurl = 'https://api.exotel.in/v1/Accounts//Calls/connect.json' +from_no = 'XXXXXXXXXXX' +to = 'XXXXXXXXXXX' +url = "http://my.exotel.com//exoml/start_voice/",