[SR-Users] Presence module with external MWI

Anthony Joseph Messina amessina at messinet.com
Mon Feb 18 23:56:58 CET 2019

On Monday, February 18, 2019 3:06:32 PM CST Trevor Peirce wrote:
> Hello,
> Looking for pointers as to what I'm missing here.
> I'm using the presence module to allow UAs to subscribe to
> message-summary events.  I can see the entries appearing in the
> active_watchers table and I see subscription renewals increment the cseq
> columns so I'm satisfied this part is working well.
> I'm having trouble finding out how to tell Kamailio about a change to
> the message-summary so that it can notify the watchers.
> The pua module seems to provide a way but it doesn't seem to work with
> the subscriptions set up by the presence module.  The presence module
> itself does not seem to offer any RPCs capable of doing this.
> Appreciate any pointers!

I use the following Python3 script with Asterisk 16 since it won't publish MWI 
natively to Kamailio (yet)

### voicemail.conf

### asterisk-kamailio-publish-mwi
# -*- coding: utf-8 -*-

import argparse
import requests

# http://kamailio.org/docs/modules/stable/modules/jsonrpcs
SIP_NEXTHOP = 'sip:'
SIP_DOMAIN = 'example.com'

class ExternNotifyHandler:

    def __init__(self, context, exten, new, old, urgent):
        Parse context, extension, and new, old, and urgent message counts


        self.context = context
        if context == 'default':
            self.context = SIP_DOMAIN

        self.exten = exten

        self.recipient = ("sip:{}@{}").format(self.exten, self.context)

        self.waiting = 'no'
        if new > 0:
            self.waiting = 'yes'

        self.body = ("Messages-Waiting: {}\r\n"
                     "Message-Account: {}\r\n"
                     "Voice-Message: {:d}/{:d} ({:d}/0)\r\n").format(
                         self.waiting, self.recipient, new, old, urgent)

    def kamailio_rpc_sip_publish(self):
        Generate a SIP PUBLISH MWI via Kamailio's jsonrpcs module
        headers = ("From: <{0}>\r\n"
                   "To: <{0}>\r\n"
                   "Max-Forwards: 1\r\n"
                   "Event: message-summary\r\n"
                   "Content-Type: application/simple-message-summary; "

        content = {
            'id': 1,
            'jsonrpc': '2.0',
            'method': 'tm.t_uac_start',
            'params': [

        # http://docs.python-requests.org/en/latest/user/quickstart/
            r = requests.post(KAMAILIO_RPC_URL, allow_redirects=False,
                              json=content, timeout=5)
        except requests.exceptions.ConnectionError as e:
        except requests.exceptions.RequestException as e:

# Main processing
if __name__ == "__main__":
    Parse Asterisk VoiceMail externnotify positional command line arguments
    context, extension, new voicemails, old voicemails, urgent voicemails
    parser = argparse.ArgumentParser()
    parser.add_argument('context', help='Voicemail context')
    parser.add_argument('exten', help='Voicemail extension')
    parser.add_argument('new', type=int, help='New voicemail count')
    parser.add_argument('old', type=int, help='Old voicemail count')
    parser.add_argument('urgent', type=int, help='Urgent voicemail count')
    args = parser.parse_args()

    p = ExternNotifyHandler(args.context, args.exten,
                            args.new, args.old, args.urgent)


Anthony - https://messinet.com
F9B6 560E 68EA 037D 8C3D  D1C9 FF31 3BDB D9D8 99B6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20190218/7c656f95/attachment.sig>

More information about the sr-users mailing list