SMPP in Telegram (Viber)

00 Intro

For many years I haven’t written anything other than notes for myself, but then an interesting solution turned out, so I decided to share it with all habr users (he participated a lot in making and finding a solution), don’t judge strictly. I will try to divide everything logically correctly, but I do not promise that it will turn out.

01 Task

There are a bunch of old pieces of iron that work using the SMPP protocol and send notifications using it to people’s phone numbers (besides, it can work directly with a GSM modem and send from it, but the 21st century is in the yard, and the cost of SMS is amazing). The costs of these notifications either became cheaper or more expensive, changed operators who provide the service quite often, these eternal searches are cheaper and better came to a logical end and it was decided to take all this somewhere for our own use, we have popular managers in the region Telegram and viber. Both have bots, both have APIs. But since I’m still an IT specialist and I don’t improve my programming skills, I will use other people’s work and experience in docking. The result is a combination that works even more interesting than it should, because. now any notifications (from 1C, freepbx, backup) can be sent directly to the chatbot by phone number.

10 Introduction

Several softins can work with smpp, I also found several server source codes on VS, tried a few and realized that the code is there, but making it work is not always a trivial task and some of them are paid, and then doing integration is still that problem, so the choice fell on channel old and crooked software. How much time it takes to make it work on a fresh distribution is a different story, but it works, and in practice it works without any problems. In general, we need an old computer (maybe a virtual machine) on board of which it is worth putting the minimum image of Centos 7, then you can simply insert commands (be careful with enabling ssh):

#disable selinux, iptables and other....
systemctl enable sshd
systemctl start sshd
yum install mc
mcedit /etc/selinux/config #edit setenforce 0
yum update
yum install gcc libxml2-devel mariadb mariadb-devel wvdial vim openssl-devel texlive-* m4 gcc-c++ make wget -y
yum groupinstall "Development tools" -y
yum remove bison -y
mkdir /usr/local/kannel/
mkdir /usr/local/kannel/src
cd /usr/local/kannel/src
wget --no-check-certificate
wget --no-check-certificate
wget --no-check-certificate
tar zxvf bison-2.7.tar.gz && cd bison-2.7 && ./configure && make && make install && cd src
cp bison /usr/local/bin/bison && cp bison /usr/bin/bison
cd /usr/local/kannel/src
tar -zxvf gateway-1.4.4.tar.gz && tar -zxvf gateway-1.4.5.tar.gz && tar -zxvf gateway-1.5.0.tar.gz
cd /usr/local/kannel/src/gateway-1.4.5
./configure  --prefix=/usr/local/kannel --enable-start-stop-daemon --with-mysql --with-mysql-dir=/usr/lib/mysql/ --enable-debug --enable-assertions --disable-localtime --enable-start-stop-daemon --enable-pam
make && make install
 cd /usr/local/kannel/src/gateway-1.4.5/addons/opensmppbox/
./configure --prefix=/usr/local/kannel --with-kannel-dir=/usr/local/kannel 
make && make install
 cd /usr/local/kannel/src/gateway-1.4.5/addons/sqlbox/
./configure --prefix=/usr/local/kannel --with-kannel-dir=/usr/local/kannel 
make && make install
systemctl stop firewalld
systemctl disable firewalld
mkdir /var/log/kannel
chmod 777 /var/log/kannel/
yum install php -y

After executing a set of these commands, you will have centos installed and working channel`ohm

11 Kannel setup

We will carry out all actions in the kannel installation directory, therefore

cd /usr/local/kannel/sbin/
touch kannel.conf
touch opensmppbox.conf
touch ouser
touch test.php

all the files have been created, let’s start setting up, I don’t see the point in telling in all respects, in theory, all this can be translated from translation to translation with the help of a translator, but you can catch the general meaning, this is a simple working config for a specific purpose:

nano kannel.conf
#и приводим файл к следующему виду:
group = core
admin-port = 13000
admin-password = test
smsbox-port = 13001
dlr-storage = internal
store-type = file
log-file = "/var/log/kannel/kannel.log"
access-log = "/var/log/kannel/access.log"
log-level = 4
store-location = "/var/log/kannel/"

group = smsbox
smsbox-id = smsboxid
bearerbox-host = localhost
sendsms-port = 13013

group = smsc
smsc = http
smsc-id = tophp
smsc-username = default
smsc-password = default
system-type = kannel
port = 63015
alt-charset = "utf-8"
send-url =
max-sms-octets = 1000
nano opensmppbox.conf
#и приводим файл к следующему виду:
group = core
dlr-storage = internal
store-type = file
store-location = "/var/log/kannel/smpp_store_sms"

group = opensmppbox
opensmppbox-id = opensmppbox
opensmppbox-port = 3700
bearerbox-host =
bearerbox-port = 13001
our-system-id = opensmppbox
smpp-logins = /usr/local/kannel/sbin/ouser
use-systemid-as-smsboxid = true
log-level = 4
log-file = /var/log/kannel/opensmppbox.log
nano ouser
#и приводим файл к следующему виду:
test1 123 user-smpp *.*.*.*
test2 123 user-smpp *.*.*.*
#и приводим файл к следующему виду:
pkill bearerbox
pkill opensmppbox
pkill php
rm /var/log/kannel/* -f
/usr/local/kannel/sbin/bearerbox /usr/local/kannel/sbin/kannel.conf
/usr/local/kannel/sbin/opensmppbox /usr/local/kannel/sbin/opensmppbox.conf
cd /tmp/ && php -S test.php

To check let’s run

/usr/local/kannel/sbin/bearerbox /usr/local/kannel/sbin/kannel.conf
/usr/local/kannel/sbin/opensmppbox /usr/local/kannel/sbin/opensmppbox.conf
cd /tmp/ && php -S

Now, from a piece of hardware, you need to send an smpp request to IP (where Kannel is running) on ​​port 3700, after which you will see a request in the console.

request from SMPP client on port 3700
request from SMPP client on port 3700

If everything worked out, great. Otherwise, you should look at the logs. (For testing, you can use the client download dll with samples, find\bin\net461\SmppClientDemo.exe in the folder)

Similar Posts

Leave a Reply