SMS Hook - BulkVS

Status
Not open for further replies.

ict2842

Member
Mar 2, 2021
139
11
18
Wichita, KS
Hey!

After seeing the slight savings of using BulkVS instead of FlowRoute ($1480 down to $330), I have decided to use BulkVS to setup FusionPBX since it will likely be the provider chosen.
I am not seeing any BulkVS SMS Hook or configuration here or online. I'm still looking around to see if I can find one, but I was wondering if one of you have created this already and didn't mind sharing. I'm somewhat trying to make my own, but I'm 100% confident I'm not doing it right.
 

hamagid

Member
Dec 14, 2020
73
6
8
33
I spent the past few hours trying to make it work, i got it to work for SMS, I'll need to play a little more to make it work for MMS as well.

For incoming SMS, go to /var/www/fusionpbx/app/sms/hook/ create a file sms_hook_bulkvs.php and paste the following code:

PHP:
<?php

include "../root.php";

require_once "resources/require.php";
require_once "../sms_hook_common.php";

if (check_acl()) {
        if  ($_SERVER['CONTENT_TYPE'] == 'application/json') {
                $data = json_decode(file_get_contents("php://input"));
                if ($debug) {
                        error_log('[SMS] REQUEST: ' .  print_r($data, true));
                }
                $to = intval(preg_replace('/(^[\+][1])/','',$data->To[0]));
                route_and_send_sms($data->From, $to, $data->Message);

        } else {
          die("no");
        }
} else {
        error_log('ACCESS DENIED [SMS]: ' .  print_r($_SERVER['REMOTE_ADDR'], true));
        die("access denied");
}
?>


In the GUI, go to advanced > access control > domains, add the IP's that bulkvs uses for SMS, as of today it's 52.206.134.245 & 192.9.236.42
 
Last edited:
  • Like
Reactions: ict2842

hamagid

Member
Dec 14, 2020
73
6
8
33
For outbound go to advanced > default settings, click the add button on top, category = sms, subcategory = carriers, type = array, value = bulkvs

Add another one, category = sms, subcategory = bulkvs_api_url, type = text, value = https://portal.bulkvs.com/api/v1.0/messageSend

Add another one, category = sms, subcategory = bulkvs_secret_key, type = text, value = Your Basic Auth Header, which you can find under API tab in your portal.

Add another one, category = sms, subcategory = bulkvs_delivery_status_webhook_url, type = text, value = https://

The last one isn't really needed, i just kept on getting errors when i was trying to avoid it so i left it and just enter https.....


Go to /etc/freeswitch/chatplan/default.xml, It should look like the following, I made it to send a auto reply if the device is not registered, you don't need that.

Code:
<?xml version="1.0" encoding="utf-8"?>
<include>
        <context name="default">
                <extension name="demo">
                        <condition field="to" expression="^(.*)$">
                                <!-- <action application="lua" data="test.lua"/> -->
                                <!-- <action application="reply" data="Hello, you said: ${_body}"/> -->
                        </condition>
                </extension>
        </context>
        <context name="public">
                <extension name="ten-digit">
                        <condition field="to" expression="^(\d{10}.*)$">
                                    <action application="set" data="final_delivery=true"/>
                                    <action application="lua" data="app.lua sms outbound"/>
                        </condition>
                </extension>
                <extension name="other">
                        <condition field="${sofia_contact(profile/${to})}" expression="error\/user_not_registered">
                                <action application="set" data="final_delivery=true"/>
                                <action application="reply" data="User is not registered, Please try again later"/>
                        </condition>
                        <condition field="to" expression="^(.*)$">
                                <action application="set" data="final_delivery=true"/>
                                <action application="send"/>
                        </condition>
                </extension>
        </context>
</include>

Go to /usr/share/freeswitch/scripts/app/sms/index.lua, somewhere around line 400 you'll find if statements for all the carriers that come by default, add the following elseif statements between the other carriers:

Code:
elseif (carrier == "bulkvs") then
                if to:len() < 11 then
                    to = "1" .. to;
                end
                if outbound_caller_id_number:len() < 11 then
                    outbound_caller_id_number = "1" .. outbound_caller_id_number;
                end
                cmd ="curl -X POST \"" .. api_url .."\" -H \"accept: application/json\" -H \"Content-Type: application/json\"  -H \"Authorization: Basic " .. secret_key .. "\" -d '{\"From\": \"" .. outbound_caller_id_number .. "\", \"To\":[ \"" .. to .. "\"], \"Message\": \"" .. body .. "\", \"delivery_status_webhook_url\": \"" .. delivery_status_webhook_url .. "\"}'";



It isn't the best code, but it does the job for me, so i thought I'll put it out here, hopefully it'll help someone.
 
Last edited:
  • Like
Reactions: pksml and ict2842
Status
Not open for further replies.