Skip to content

Instantly share code, notes, and snippets.

@D4rk4
Forked from codexss/smstools3.md
Created December 14, 2017 16:44
Show Gist options
  • Save D4rk4/416b19cd19233bcd60f5a8ed1352af29 to your computer and use it in GitHub Desktop.
Save D4rk4/416b19cd19233bcd60f5a8ed1352af29 to your computer and use it in GitHub Desktop.
Openwrt/LEDE smstools3 forward sms to telegram
opkg update
opkg install kmod-usb-serial kmod-usb-serial-wwan kmod-usb-serial-option usb-modeswitch smstools3 curl iconv

vi /usr/local/bin/pushsms

#!/bin/sh

chat_id=xxxxxxxx
token=xxxxxxxx

if [ "$1" == "RECEIVED" ]; then
    from=`grep "From:" $2 | awk -F ': ' '{printf $2}'`
    #sent=`grep "Sent:" $2 | awk -F ': ' '{printf $2}'`
    #received=`grep "Received:" $2 | awk -F ': ' '{printf $2}'`
    alphabet=`grep "Alphabet:" $2 | awk -F ': ' '{printf $2}'`

    if [ "$alphabet" = "UCS2" ]; then
        content=$(sed -e '1,/^$/ d' < "$2" | iconv -f UNICODEBIG -t UTF-8)
    else
        content=$(sed -e '1,/^$/ d' < "$2")
    fi

    text=$(cat <<EOF
$content
From $from
EOF
)

    curl -d "chat_id=$chat_id&text=$text" -X POST https://api.telegram.org/bot"$token"/sendMessage

fi

vi /etc/smsd.conf

#
# Description: Main configuration file for the smsd
#

devices = GSM1
incoming = /var/spool/sms/incoming
outgoing = /var/spool/sms/outgoing
checked = /var/spool/sms/checked
failed = /var/spool/sms/failed
sent = /var/spool/sms/sent
receive_before_send = no
autosplit = 3
loglevel = notice
#delaytime = 0
eventhandler = /usr/local/bin/pushsms

[GSM1]
init = AT+CPMS="ME","ME","ME"
device = /dev/ttyUSB1
incoming = yes
#pin = 0000
baudrate = 9600
signal_quality_ber_ignore = yes
detect_unexpected_input = no
memory_start = 0

/etc/init.d/smstools3 restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment