Skip to content

Commit d6d96a6

Browse files
committed
ppinfo-yatescript: continuously speak the PP ID that a PP is connected to
1 parent d40ea0e commit d6d96a6

17 files changed

Lines changed: 79 additions & 0 deletions

File tree

ppinfo-yatescript.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Obtains the incoming caller number from Yate, finds the associated PP, and
5+
continuously TTS-speaks the ID of the RFP the PP is connected to.
6+
"""
7+
8+
import asyncio
9+
import datetime
10+
import logging
11+
import os
12+
import re
13+
import uuid
14+
15+
import sys
16+
import configparser
17+
18+
from OMMClient.OMMClient import OMMClient
19+
20+
import requests
21+
from yate.protocol import MessageRequest
22+
from yate.ivr import YateIVR
23+
24+
25+
async def main(ivr: YateIVR):
26+
config = configparser.ConfigParser()
27+
config.read('pmu.ini')
28+
omm_ip = config['DEFAULT'].get('omm_ip')
29+
omm_port = config['DEFAULT'].getint('omm_port', 12622)
30+
omm_username = config['DEFAULT'].get('omm_username', 'omm')
31+
omm_password = config['DEFAULT'].get('omm_password')
32+
SOUNDS_PATH = config['DEFAULT'].get('sounds_path', '/opt/sounds')
33+
34+
caller_id = ivr.call_params.get("caller", "")
35+
caller_id = re.sub("[^\\d]", "", caller_id)
36+
caller_id = re.sub("^\\+", "00", caller_id)
37+
38+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "intro.slin"), complete=True)
39+
await asyncio.sleep(0.5)
40+
41+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", "TLN.slin"), complete=True)
42+
for digit in caller_id:
43+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", digit+".slin"), complete=True)
44+
45+
client = OMMClient(omm_ip, omm_port)
46+
client.login(omm_username, omm_password)
47+
48+
if not client:
49+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", "OMM.slin"), complete=True)
50+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", "unbekannt.slin"), complete=True)
51+
sys.exit(0)
52+
53+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", "PP.slin"), complete=True)
54+
u = client.find_user({'num': caller_id})
55+
if not u:
56+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", "unbekannt.slin"), complete=True)
57+
sys.exit(0)
58+
for digit in str(u.ppn):
59+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", digit+".slin"), complete=True)
60+
61+
previous_rfp = None
62+
while True:
63+
a = client.get_last_pp_dev_action(u.ppn)
64+
rfp = a.rfpId if a else None
65+
if rfp != previous_rfp:
66+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", "RFP.slin"), complete=True)
67+
if not rfp:
68+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", "unbekannt.slin"), complete=True)
69+
sys.exit(0)
70+
for digit in str(rfp):
71+
await ivr.play_soundfile(os.path.join(SOUNDS_PATH, "parts", digit+".slin"), complete=True)
72+
previous_rfp = rfp
73+
74+
await asyncio.sleep(2)
75+
76+
77+
app = YateIVR()
78+
app.run(main)
79+

sounds/intro.slin

13.9 KB
Binary file not shown.

sounds/parts/0.slin

10.2 KB
Binary file not shown.

sounds/parts/1.slin

10.4 KB
Binary file not shown.

sounds/parts/2.slin

10.8 KB
Binary file not shown.

sounds/parts/3.slin

9.57 KB
Binary file not shown.

sounds/parts/4.slin

9.07 KB
Binary file not shown.

sounds/parts/5.slin

10.7 KB
Binary file not shown.

sounds/parts/6.slin

10.7 KB
Binary file not shown.

sounds/parts/7.slin

10.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)