Last active
February 24, 2022 16:16
Star
You must be signed in to star a gist
POC for using SMS webhook in FreePBX to send to if this then that ifttt.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/***************************************************** | |
* Rough proof of concept of a web script | |
* to accept SMS webhook from FreePBX on an | |
* inbound SMS and post it to twitter using an https://ifttt.com/ webhook | |
* | |
* License: GNU GPL3+ | |
* | |
* History : 2022-01-13 first commit | |
* 2022-01-16 clean up and comment | |
* | |
****************************************************/ | |
// Edit these valuse wiht your IFTTT webhook params | |
$key="iftttkey"; | |
$applet_name="ifttt_aplet_name"; | |
/* Parse POST data into array. SMS will be this format | |
Array | |
( | |
[to] => <DID> | |
[from] => <CallerID> | |
[adaptor] => Sipstation | |
[time] => Wed,_31_Dec_1969_20:00:00_-0400 | |
[message] => This_is_a_test_SMS | |
[eventDirection] => in | |
) | |
MMS Array looks like this | |
Array | |
( | |
[to] => <DID> | |
[from] => <CallerID> | |
[adaptor] => Sipstation | |
[time] => Wed,_31_Dec_1969_20:00:00_-0400 | |
[message] => Array | |
( | |
[mediaUrl] => http://<redacted>:80/admin/api/api/rest/sms/media/8 | |
) | |
[eventDirection] => out | |
) | |
*/ | |
$foo = array_keys($_POST); | |
$sms_array=json_decode($foo[0],true); | |
logwrite(print_r($sms_array,true)); | |
$val1='XXXXXX'.substr($sms_array['from'], -4); //obfuscate CID number | |
$val2 = str_replace("_"," ",$sms_array['message']); // clean up message string | |
logwrite("from: $val1"); | |
logwrite("message: $val2"); | |
// send to IFTTT webhook | |
$url = "https://maker.ifttt.com/trigger/$applet_name/with/key/$key"; | |
$ch = curl_init($url); | |
$xml = "value1=$val1&value2=$val2"; | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
function logwrite($data) { | |
echo "Writing to log"; | |
file_put_contents("/var/log/asterisk/sms2tweet.log",$data."\n",FILE_APPEND); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment