Python script for asterisk voicemail function

Closed - This job posting has been filled and work has been completed.
Web, Mobile & Software Dev Scripts & Utilities Posted 2 years ago

Fixed Price

Delivery by May 10, 2013

$20.00

Budget

Details

This script, monitors a mailbox and if there is a new message, it makes a call to a pager number and enters a code (here the code is 301 which will appear on the pager). We want to make these changes:
After three minutes, the script checks the mailbox again and if the message is still there, it will make another call to pager 1 and pager 2 (both with pause the then the code 301)
After another three minutes the script checks the mailbox again and if the message is still there, it will make a call to pager 1 and pager 2 and pager 3.
Every three minutes the script checks and if the message is still there will page the three pagers until the message is removed from the mailbox.

During this situation if a new message is left in the same mailbox, the script should follow the above process from scratch: “and if there is a new message, it makes a call to a pager number and enters a code”




#!/bin/env python
import sys, os, logging, telnetlib

#Access to AMI on asterisk
MANAGER_USER = "admin"
MANAGER_PORT = "5038"
MANAGER_HOST = "127.0.0.1"
MANAGER_PASS = "amp111"

MONITOR_EXT = '301'
DST         = '17037020373'

PAUSE_1   = '3'
PAGER_EXT = '301'
PAUSE_2   = '4'

#Call legs
LEG_1_CONTEXT = 'vm_notify_leg1'
LEG_2_CONTEXT = 'vm_notify_leg2'

#Log file
LOG_FILE = '/tmp/vm.log'
LOG_APP  = 'dialer'

# Additional functions
def log(message):
     try:
            logger = logging.getLogger(LOG_APP)
            hdlr = logging.FileHandler(LOG_FILE)
            formatter = logging.Formatter('%(asctime)s: %(message)s')
            hdlr.setFormatter(formatter)
            logger.addHandler(hdlr)
            logger.setLevel(logging.WARNING)
            logger.error(message)
     except:
         pass

EXT = sys.argv[2]

if sys.argv[2] == MONITOR_EXT:
    log("VM for our %(EXT)s" %vars())

    try:
        t = telnetlib.Telnet()
        t.open(MANAGER_HOST,MANAGER_PORT)
    except Exception, e:
        log("Error: %(e)s" %vars())
        sys.exit()

    EOL = '\r\n'
    LOGIN = ['Action: login','Username: %s' % MANAGER_USER,'Secret: %s' % MANAGER_PASS, 'Events: on', '\r\n']

    try:
        t.write(EOL.join(LOGIN))
    except Exception, e:
        log("Error: %(e)s" %vars())
        sys.exit()

    DIALOUT = ['Action: Originate', 'Channel: Local/s@%(LEG_1_CONTEXT)s/n' %vars() ,
               'Context: %(LEG_2_CONTEXT)s' %vars(), 'Extension: s' , 'Priority: 1',
               'Variable: DST=%s' %DST,
               'Variable: PAUSE_1=%s' %PAUSE_1,
               'Variable: PAGER_EXT=%s' %PAGER_EXT,
               'Variable: PAUSE_2=%s' %PAUSE_2,
               '\r\n' ]
    try:
        log("Dialing ...")
        t.write(EOL.join(DIALOUT))
    except Exception,e:
        log("Connection try out for AMI. Cause: %(e)s" %vars())

     
else:
     pass

---
Skills: linux, import


About the Client

(4.78) 37 reviews

United States
Arlington 01:08 PM

69 Jobs Posted
73% Hire Rate, 1 Open Job

$9,402 Total Spent
52 Hires, 3 Active

$9.98/hr Avg Hourly Rate Paid
390 Hours

Member Since Dec 15, 2011