Forráskód Böngészése

SMS add support for teli, plivo and logging results of curl (#21)

* add sms_delete

* add chatplan

add the chaplain

* SMS add support for teli, plivo and logging results of curl

SMS add support for teli, plivo and logging results of curl
Chris Black 9 éve
szülő
commit
0ea30f6c3b

+ 9 - 2
sms/app_defaults.php

@@ -48,8 +48,15 @@ if ($domains_processed == 1) {
 	$array[$x]['default_setting_enabled'] = 'true';
 	$array[$x]['default_setting_description'] = '';
 	$x++;
-
 	$array[$x]['default_setting_category'] = 'sms';
+	$array[$x]['default_setting_subcategory'] = 'carriers';
+	$array[$x]['default_setting_name'] = 'array';
+	$array[$x]['default_setting_value'] = 'plivo';
+	$array[$x]['default_setting_enabled'] = 'true';
+	$array[$x]['default_setting_description'] = '';
+	$x++;
+
+/*	$array[$x]['default_setting_category'] = 'sms';
 	$array[$x]['default_setting_subcategory'] = 'flowroute_access_key';
 	$array[$x]['default_setting_name'] = 'text';
 	$array[$x]['default_setting_value'] = '';
@@ -93,7 +100,7 @@ if ($domains_processed == 1) {
 	$array[$x]['default_setting_enabled'] = 'false';
 	$array[$x]['default_setting_description'] = '';
 	$x++;
-
+*/
 		
 	//get an array of the default settings
 		$sql = "select * from v_default_settings ";

+ 19 - 0
sms/hook/sms_hook_plivo.php

@@ -0,0 +1,19 @@
+<?php
+
+include "../root.php";
+
+require_once "resources/require.php";
+require_once "../sms_hook_common.php";
+
+if (check_acl()) {
+	if  ($_SERVER['REQUEST_METHOD'] == 'POST') {
+		//error_log('REQUEST: ' .  print_r($_REQUEST, true));
+		route_and_send_sms($_REQUEST['From'], str_replace("+","",$_REQUEST['To']), $_REQUEST['Text']);
+	} else {
+	  die("no");
+	}
+} else {
+	error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
+	die("access denied");
+}
+?>

+ 14 - 1
sms/resources/install/scripts/app/sms/index.lua

@@ -207,11 +207,24 @@
 			cmd = "curl -u ".. access_key ..":" .. secret_key .. " -H \"Content-Type: application/json\" -X POST -d '{\"to\":\"" .. to .. "\",\"from\":\"" .. outbound_caller_id_number .."\",\"body\":\"" .. body .. "\"}' " .. api_url;
 		elseif (carrier == "twilio") then
 			cmd ="curl -X POST '" .. api_url .."' --data-urlencode 'To=+" .. to .."' --data-urlencode 'From=+" .. outbound_caller_id_number .. "' --data-urlencode 'Body=" .. body .. "' -u ".. access_key ..":" .. secret_key .. " --insecure";
+		elseif (carrier == "teli") then
+			cmd ="curl -X POST '" .. api_url .."' --data-urlencode 'destination=" .. to .."' --data-urlencode 'source=" .. outbound_caller_id_number .. "' --data-urlencode 'message=" .. body .. "' --data-urlencode 'token=" .. access_key .. "' --insecure";
+		elseif (carrier == "plivo") then
+			if to:len() <11 then
+				to = "1"..to;
+			end
+			cmd="curl -i --user " .. access_key .. ":" .. secret_key .. " -H \"Content-Type: application/json\" -d '{\"src\": \"" .. outbound_caller_id_number .. "\",\"dst\": \"" .. to .."\", \"text\": \"" .. body .. "\"}' " .. api_url;
 		end
 		if (debug["info"]) then
 			freeswitch.consoleLog("notice", "[sms] CMD: " .. cmd .. "\n");
 		end
-		os.execute(cmd)
+		local handle = io.popen(cmd)
+		local result = handle:read("*a")
+		handle:close()
+		if (debug["info"]) then
+			freeswitch.consoleLog("notice", "[sms] CURL Returns: " .. result .. "\n");
+		end
+--		os.execute(cmd)
 
 	end