Get SMS from USB modem and send them to Telegram

Is there any way to get SMS from a Huawei E3372 modem and send them to Telegram via webhook?

Yeah something like this (replace openwrt commands with telegram webkooks) [HOW-TO] Send commands to the router with SMS messages (Asterisk)

There's a smstools3 package, in the repository, for getting the SMSes.

Posting them in telegram, is probably a one liner using curl.

Yes, smstools3 should do the job. But attention. There are different versions of E3372 available.
You will need a version acting as modem. Not in HILink mode.
Just plugin the stick and check if you got a device /dev/ttyUSBn ...

When everything works as expected create a event-handler script as described in smstools3.

I did it the same way to forward SMS Messages via signal-cli.
But I'm using a buggy E160 which stops receiving SMS from time to time :frowning:

I would be happy if you report here whether it runs reliably with the E3372.

This is where the problems may arise. The provider limits the ability to distribute the Internet, so you have to use modified firmware, which is available only for HiLink. From HiLink it is impossible to get SMS and do webhook?

I would also like to clarify, I will need to have some curl, which will check the SMS or it will happen automatically?

I have no experience with telegram because I prefer Signal. But it should be simple to create a script to send messages. i.e look here.
Of course building the script is your turn

In global section of smsd.conf you have to define a script, that should be run, when a SMS is received:

eventhandler = /etc/scripts/smsd_event.sh 

And of course building the event handler script is your turn again.
Something like this.

#!/bin/sh                                                                                                                                                          
# $1 is the type of the event wich can be SENT, RECEIVED, FAILED or REPORT.                                                                                        
# $2 is the filename of the sms.                                                                                                                                   
# $3 is the message id. Only used for SENT messages with status report.                                                                                            
                                                                                                                                                                                                                                                                                                                                     
if [ "$1" == "RECEIVED" ]; then                                                                                                                                    
# read received SMS line by line                                                                                                                              
        while IFS= read -r line || [ -n "$line" ]                                                                                                                  
        do                                                                                                                                                         
                if [ -z "${BODY+set}" ]; then                                                                                                                      
                # variable BODY not defined                                                                                                                
                                                                                                                                                                   
                        # separate key-value pairs                                                                                                      
                        KEY=$(echo ${line} | cut -d':' -f1 )                                                                                                       
                        VAL=$(echo ${line} | cut -d':' -f2- | cut -d' ' -f2- )                                                                                     
                                                                                                                                                                   
                        case "$KEY" in                                                                                                                             
                                From)                                                                                                                              
                                        FROM="$VAL"                                                                                                                
                                        ;;                                                                                                                         
                                Sent)                                                                                                                              
                                        SENT="$VAL"                                                                                                                
                                        ;;                                                                                                                         
                                Length)                                                                                                                            
                                        # Data behind Lenght belong to body, so define BODY here                            
                                        BODY="\n"                                                                                                                  
                                        ;;                                                                                                                         
                        esac                                                                                                                                       
                else                                                                                                                                               
                        # append every body line                                                                                                     
                        BODY="${BODY}${line}"                                                                                                                      
                fi                                                                                                                                                 
        done < $2                                                                                                                                                  
                                                                                                                                                                   
        # If we got a body, then forward
        if [ -n "${BODY}" ]; then                                                                                                                                  
                echo "=> forwarding SMS now"
.....
                # rename file
                mv $2 $2.forwarded                                                                                                               
        else                                                                                                                                                       
                echo "no mail body found"                                                                                                                
        fi                                                                                                                                                         
                                                                                                                                                                   
        # delete oldest *.forwarded files, but keep 5 files                                                                                                           
        cd /var/spool/sms/incoming                                                                                                                                       
        ls -1t *.mailed 2>/dev/null | tail -n +6 | xargs rm -f                                                                                                     
fi                                                                                                                                                                 
exit 0                                                                                                                                                             

I did not know, if a E3372H (H=HILink) will work. But a E3372S (S=serial) should work. Maybe its possible to flash from H to S firmware.

it is ...

https://www.0xf8.org/2017/01/flashing-a-huawei-e3372h-4g-lte-stick-from-hilink-to-stick-mode/

1 Like

I have done some tests with 3 different old HUAWEI dongles now.
I have connected them to a NanoPi R2S running OpenWrt 21.02.3 ans smstools3. All of them are working out of the box.
They are available in germany on ebay-kleinanzeigen.de for about 5€ - 10€.

To test performance I have send 100 SMS to 7 different receivers in german telekom network (Ja!Mobil SIM)

E160
Very slow. Seems to stop suddenly working, depending of configuration.
More investigation has to be done...
E1750
Much faster then E160. Reliable for more then 3 day's now.
E173
Little faster then E1750. Reliable for more then 3 day's now.

1 Like