Δευτέρα 9 Μαρτίου 2015

Getting a SIP call whenever an IFTTT recipe is triggered

In my previous post I explained how to run a custom script triggered by an IFTTT reipe.
In this post I will explain how to get a SIP call when an IFTTT action is triggered.

I assume you have created the recipe, linked Dropbox and configured incrontab as explained here.

Requirements:
-A cli SIP client, pjsua (from the pjsip library) is perfect for this job
-expect package (in order to "talk" to pjsua with spawn)
-festival package (this includes text2wave for text-to-speech)

I didn't find pjsip as a package for Debian, so I had to download it from http://www.pjsip.org and compile it manually, it's straightforward (configure-make dep-make).
pjsua is located inside the /pjsip-apps folder so you may either copy it somewhere convenient or create a soflink in order to run it.

Create your pjsip conf file (this may depend on your SIP provider) and paste:

--null-audio
--registrar sip:your.sip.provider.com
--realm=*
--id sip:sipuser@your.sip.provider.com
--username sipuser
--password yourpass
--auto-play
--max-calls 1

You may at first check that you can make a SIP call:
pjsua sip:1234567890@your.sip.provider.com --config-file /home/bob/pjsip.conf 

Then edit your script.sh file: (I found this script somewhere on the web and did slight modifications to it)

#! /bin/bash

EXPECT=/usr/bin/expect
SOUNDFILE=/tmp/alert.wav
TEXT2WAVE=/usr/bin/text2wave
DURATION=20
MESSAGE="Monitoring Alert"
PJSUACONFIG=/home/bob/pjsip.conf
CALLNUMB=1234567890

locked=false
 while [[ $locked == false ]]; do
     if [[ ! -f /tmp/caller.lock ]]; then
         touch /tmp/caller.lock
         locked=true
     else
         sleep 5
     fi
 done

# Generating the message
$TEXT2WAVE -o $SOUNDFILE -f 8000 << EOF
$MESSAGE
EOF

$EXPECT << EOF
spawn pjsua sip:$CALLNUMB@your.sip.provider.com --config-file $PJSUACONFIG --play-file $SOUNDFILE --duration $DURATION
expect "VAD re-enabled"
sleep 1
send "q\n"
EOF

# Cleaning up
rm $SOUNDFILE

# Removing the lock file and IFTTT file
rm /tmp/caller.lock
rm /home/bob/Dropbox/IFTTT/runme*

That's it!


Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου