Repository is archived
No commit activity in last 3 years
No release in over 3 years
Asterisk voicemail emails enhancement
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 1.3
>= 0
>= 0
>= 0

Runtime

>= 0
~> 1.2.6
 Project Readme

Asterisk::Mailcmd

Build Status Code Climate Gem Version

Extending Asterisk voicemail message body for emails

Asterisk Voicemail email seems to be quite limited when it comes about configuring email body:

  • Email body is a one line text with backslash escapes and Asterisk variables.
  • It is limited to 512 characters (see voicemail.conf.sample)

Under these circumstances it is impossible to create nice looking, formatted emails, to have individual email templates per user or multi-languages emails' templates.

This simple a simple library which is supposed to address these shortcomings.

HTML Voicemail notification example

html email

Installation

Library for your application

Add this line to your application's Gemfile:

gem 'asterisk-mailcmd', :git => git://github.com/staskobzar/asterisk-mailcmd.git

And then execute:

$ bundle

Command line application

Or install it yourself as:

$ git clone git://github.com/staskobzar/asterisk-mailcmd.git
$ cd asterisk-mailcmd
$ gem build asterisk-mailcmd.gemspec
$ gem install asterisk-mailcmd-X.X.X.gem

Asterisk configuration

Asterisk voice mail must be configured to run this library when new voicemail received. There is an option mailcmd in voicemail.conf which must link to the executable script with this library:

mailcmd=/usr/local/bin/mailcmd

Another option that must be set is the mailbody :

emailbody=VM_NAME:${VM_NAME}\nVM_DUR:${VM_DUR}\nVM_MSGNUM:${VM_MSGNUM}\nVM_MAILBOX:${VM_MAILBOX}\nVM_CALLERID:${VM_CALLERID}\nVM_CIDNUM:${VM_CIDNUM}\nVM_CIDNAME:${VM_CIDNAME}\nVM_DATE:${VM_DATE}\nVM_MESSAGEFILE:${VM_MESSAGEFILE}

This is a list of variables that will be used in ERB templates.

You can not use asterisk-mailcmd CLI application installed with this gem directly as a reference in in option mailcmd because Asterisk when asterisk run the command, it will not have information about your environment like path to ruby interpreter. For that you must have a wrapper. Example of the wrapper can be found with the source: "sample/mailcmd.rvm.sh". Here is sample code:

#!/bin/sh

# This is as simple wrapper for ruby application asterisk-mailcmd
# when using RVM (Ruby Version Manager: https://rvm.io/) 

# path to HTML and TEXT templates in ERB format
# see samples in "sample" directory
HTML_TMPL=/etc/asterisk/vmtemplate/html.erb
TEXT_TMPL=/etc/asterisk/vmtemplate/text.erb

# load RVM profile
source /etc/profile.d/rvm.sh
# run mail command
asterisk-mailcmd -t $TEXT_TMPL -m $HTML_TMPL

exit 0

Save this to file /usr/local/bin/mailcmd, just like it is set with mailcmd option. Make sure that the file is executable.

Ruby gem library

You can create your own ruby script:

require 'asterisk/mailcmd'

Asterisk::Mailcmd::Email.set_and_send :text_tmpl => '/path/text.erb',
                                      :html_tmpl => '/path/html.erb'

Asterisk::Mailcmd::Email.set_and_send parameters list:

:html_tmpl  => String: MANDATORY: HTML part ERB template file path
:text_tmpl  => String: MANDATORY: Text part ERB template file path
:charset    => String: OPTIONAL: Content type charset
:date       => Time: OPTIONAL: Email date

Templates

Templates are ERB format with variables that are set with Asterisk (see option mailbody):

<h1>There is new mail in mailbox: <%= @astvars[:VM_MAILBOX].to_s %> </h1>

There are two example files in directory sample.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request