Skip to content

Commit

Permalink
ASTERSIK2ROCKETCHAT is ON!
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanogueira committed Feb 17, 2022
1 parent 50be23e commit 9c16932
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
62 changes: 62 additions & 0 deletions rocket_connect/utils/asterisk2rocketchat/asterisk2rocketchat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import asyncio

import requests
from panoramisk import Manager

#
# AMI CONF in ASTERISK
#
# add this below, adapting permit and deny accordingly
# to /etc/asterisk/manager_custom.conf
# [queue_alert_user]
# secret=queue_alert_pwd
# deny=0.0.0.0/0.0.0.0
# permit=0.0.0.0/0.0.0.0
# read = all
# eventfilter=Event: QueueCallerAbandon

manager = Manager(
loop=asyncio.get_event_loop(),
host="localhost",
username="queue_alert_user",
secret="queue_alert_pwd",
)
#
# you need to create the above webhook in Rocket.Chat
# and paste the Script from incoming.webhook.Rocket.Chat.js
# this is the webhook url
incoming_endpoint = (
"http://localhost:3000/hooks/"
+ "620e9615701ffe000986a1c8/8fRecuRk5Muyf3mtsGtDGFgJDkZ8wuEjm5qNqNFqxuCLaErE"
)

# this is an example.
# you can filter the callback by different method
# or inside the method, using message.event
# you can also duplicate the code below, and send different
# events to differents webhooks / channels / users


@manager.register_event("QueueCallerAbandon")
def callback(manager, message):
if "FullyBooted" not in message.event:
"""This will print every event, but the FullyBooted events as these
will continuously spam your screen"""
# event = message.event
# if event == "QueueCallerAbandon":
# if event == "OtherEvent":
payload = dict(message.items())
print(payload)
requests.post(incoming_endpoint, json=payload)


def main():
manager.connect()
try:
manager.loop.run_forever()
except KeyboardInterrupt:
manager.loop.close()


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* exported Script */
/* globals console, _, s */

class Script {
/**
* @params {object} request
*/
process_incoming_request({ request }) {
return {
content:{
text: [
':no_mobile_phones: *Abandoned Call*',
':passport_control: *Queue*: ' + request.content.Queue,
':calling: *Caller Number:*: ' + request.content.CallerIDNum,
':alarm_clock: *Hold Time*: ' + request.content.HoldTime + 's',
':vertical_traffic_light: *Entered at position* ' + request.content.OriginalPosition + '. Abandoned at ' + request.content.Position,
].join('\n')
}
};
}
}
2 changes: 2 additions & 0 deletions rocket_connect/utils/asterisk2rocketchat/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
panoramisk==1.4
mysql-connector-python==3.6.1

0 comments on commit 9c16932

Please sign in to comment.