Page 1 of 1

Check Asterisk extension for Voicemail over IRC Rate Topic: -----

#1 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Post icon  Posted 19 March 2021 - 09:02 AM

So one day idling on IRC I thought that it might be fun if I could request from an EggDrop Bot for voicemail on my Asterisk server.

To accomplish this, requires that ssh keys to be setup between the irc EggDrop server and the Asterisk server. This allows for a streamlined connection without prompting for a password.

If you are unfamiliar with tcl scripting, it's a pretty old scripting language that was most often found used to write EggDrop (irc) bot scripts. The bind determines it's trigger as well as it's requirements for user level. For my example, it requires chan ops, if we trust a user enough with our channel, then we trust them to check an extension for voicemail. Anything less, & I don't want them trying to guess what extensions exist.

The tcl script/Eggdrop bot
bind PUB - !voicemail voicemail

proc voicemail {nick uhost hand chan exten} {
  putlog "\[TRIGGERED\] $nick - $chan - $exten"
  if {[isop $nick $chan]} {
    set result [exec ssh calls "bash $exten"]
    putlog "\[FETCHED\] $result"
    putserv "PRIVMSG $chan :$result"
  } else {
    putlog "\[FAILED\] Triggered by non-op!"

putlog "\[LOADED\] VoiceMail v0.1 by \002no2pencil ([email protected])\002"

The script checks if the user is an op, & if so logs that they requested, makes the ssh call to our shell script, collects the results returned, & prints them to the channel. Pretty simple.

The Bash Shell code

The bash shell scrip that I wrote for this project is just as simple. It takes a single argument, the extension, checks the number of txt files (1 per voicemail), & collects that number to evaluate if we're going to say "voicemail" or "voicemails". It then collects a little bit of data on the oldest voicemail which will be named 000.txt. The results are then echo'ed out, which conveniently returns that data to the calling ssh connection.


if [ ! $1 ]; then
  echo "No Extension was provided"
  exit 1


vmcount=$(ls -l /var/spool/asterisk/voicemail/main/$1/INBOX/*.txt 2> /dev/null|wc -l|awk '{print $1}')
if [ ${vmcount} -gt 1 ]; then

vm=$(ls ${vmfile} 2>&1 /dev/null)
if [ $? -eq 0 ]; then
  callerid=$(cat ${vmfile}|grep '^callerid'|cut -d'=' -f2-)
  origdate=$(cat ${vmfile}|grep '^origdate'|cut -d'=' -f2-)
  echo "Extension $1 has ${vmcount} NEW voicemail${s}, the oldest from ${callerid} on ${origdate}!"
  echo "There is currently no NEW voicemail for extension $1"

Instructions for deployment
Copy the tcl script (VoiceMail.tcl) to your EggDrop scripts directory
Add the tcl script (VoiceMail.tcl) to your EggDrop config and the restart the EggDrop service
Place the bash shell script ( in your Asterisk home directory
User Requesting Voicemail must be a chan-op in the channel making the request

Example usage


15:50 <@no2pencil> !voicemail 1007
15:50 <@Alfred> Extension 1007 has 3 NEW voicemails from "INBOUND (313)209-7522" <+13132097522> on Wed Jul 19 02:10:03 PM UTC 2017!

15:50 <@no2pencil> !voicemail 6000
15:50 <@Alfred> There is currently no NEW voicemail for extension 6000

Link to GitHub repository : irc-voicemail

Is This A Good Question/Topic? 3
  • +

Page 1 of 1