📜 ⬆️ ⬇️

A simple sms bot on the shell

i am bot
Hello, dear habrovchane!
The other day I wrote a simple bot for SMS correspondence. He can receive incoming messages, process them and (if words from the message are in his "memory") send back logical answers.

All I needed:

- Ubuntu 12.04 on a home computer
- Installed gnokii (see how to install it here )
- shell script
- cron, regularly launching this script
- a phone with money in the account (almost any old Nokia with bluetooth will fit, as well as SonyEricsson k series)
- Bluetooth adapter
- a couple of hours of free time.
A plus was the lack of need for an Internet connection.

If you are interested - please under the cat.
')
So, I’ll start by describing the general logic of the application so that it is immediately clear what and why.

There is a third party A.
There is our phone - subscriber B.

Our actions.


1) Subscriber B is mated with a computer via bluetooth using standard phone facilities, we allow it to automatically authorize.

2) Install gnokii.

3) Create and grant permissions to the sms_bot.sh script:
#!/bin/bash inp=$(gnokii --getsms IN 1 end) #     echo $inp>/home/light204/Desktop/inp.txt #     counter_love=$(grep -c  /home/light204/Desktop/inp.txt) #     counter_luba=$(grep -c  /home/light204/Desktop/inp.txt) #     counter_hello=$(grep -c  /home/light204/Desktop/inp.txt) #     counter_good=$(grep -c  /home/light204/Desktop/inp.txt) #     counter_name=$(grep -c  /home/light204/Desktop/inp.txt) #     killall gnokii # gnokii,        #    ,     ,     . if [ "$counter_love" == "1" ]; then echo "  ,    !!! ( )" | gnokii --sendsms '+7904xxxxxx' elif [ "$counter_luba" == "1" ]; then echo ", ,    :)" | gnokii --sendsms '+7904xxxxxx' elif [ "$counter_hello" == "1" ]; then echo "  !   ?" | gnokii --sendsms '+7904xxxxxx' elif [ "$counter_good" == "1" ]; then echo " ,     !  , ,     :(" | gnokii --sendsms '+7904xxxxxx' elif [ "$counter_name" == "1" ]; then echo " Light204_comp .   ,  ;)" | gnokii --sendsms '+7904xxxxxx' fi sleep 3 killall gnokii # gnokii,        gnokii --deletesms IN 1 end #   #.       


4) We configure cron to run the sms_bot.sh script every minute, for example.

5) The system should earn. Subscriber A sends SMS to subscriber B. Telephone of subscriber B accepts incoming SMS, it is read by the script, analyzes, sends the answer to subscriber A, removes sms from subscriber A.

PS My script is far from perfect, but it is rather a test version to work. In addition, I think that the complex described here is unlikely to be needed by someone “as is”, but you may be able to remake and / or adapt it to fit your needs.

Source: https://habr.com/ru/post/151698/


All Articles