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 externnotify=/usr/bin/asterisk-kamailio-publish-mwi
### asterisk-kamailio-publish-mwi #!/usr/bin/python3 # -*- coding: utf-8 -*-
import argparse import requests
# http://kamailio.org/docs/modules/stable/modules/jsonrpcs KAMAILIO_RPC_URL = 'http://<KAMAILIO IP>:5060/RPC' SIP_NEXTHOP = 'sip:127.0.0.1:5060' 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; " "charset=utf-8\r\n").format(self.recipient)
content = { 'id': 1, 'jsonrpc': '2.0', 'method': 'tm.t_uac_start', 'params': [ 'PUBLISH', self.recipient, SIP_NEXTHOP, '.', headers, self.body ] }
# http://docs.python-requests.org/en/latest/user/quickstart/ try: r = requests.post(KAMAILIO_RPC_URL, allow_redirects=False, json=content, timeout=5) r.raise_for_status() except requests.exceptions.ConnectionError as e: print(e) pass except requests.exceptions.RequestException as e: print(e) pass
# 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)
p.kamailio_rpc_sip_publish()