Hal De před 4 roky
rodič
revize
8ae7c183f5
1 změnil soubory, kde provedl 17 přidání a 1 odebrání
  1. 17 1
      app/app.py

+ 17 - 1
app/app.py

@@ -165,7 +165,23 @@ async def presenceStatusCallback(mngr: Manager, msg: Message):
 
 @manager.register_event('Newchannel')
 async def newchannelCallback(mngr: Manager, msg: Message):
-  app.logger.warning(pformat(msg))
+  if (msg.channelstate == '4') and (msg.exten in app.cache['devicemap']) and ('HTTP_CLIENT' in app.config):
+    user = msg.exten
+    device = app.cache['devicemap'][user]
+    if msg.calleridnum in app.cache['usermap']:
+      cid = app.cache['usermap'][msg.calleridnum]
+    else:
+      cid = msg.calleridnum
+    uid = msg.uniqueid
+    row = await db.fetch_one(query='SELECT url FROM callback_urls WHERE device = :device',
+                             values={'device': app.cache['devicemap'][user]})
+    if row is not None:
+      reply = await app.config['HTTP_CLIENT'].post(row['url'],
+                                                   json={'user': user,
+                                                         'device': device,
+                                                         'state': 'ringing',
+                                                         'callerId': cid,
+                                                         'uniqueId': uid})
 
 async def getCDR(start=None,
                  end=None,