Hal De 3 年 前
コミット
fb5ea83555
1 ファイル変更36 行追加3 行削除
  1. 36 3
      app/app.py

+ 36 - 3
app/app.py

@@ -1,10 +1,12 @@
 #!/usr/bin/env python3
+
 import asyncio
 import aiohttp
 import logging
 import os
 import re
 import json
+from datetime import date as date
 from datetime import datetime as dt
 from datetime import timedelta as td
 from typing import Any, Optional
@@ -221,9 +223,16 @@ async def celCallback(mngr: Manager, msg: Message):
     if ('transferee_channel_uniqueid' in extra) and ('channel2_uniqueid' in extra):
       first = extra['transferee_channel_uniqueid']; #unique
       second = extra['channel2_uniqueid']   #linked
-      #amiStopMixMonitor(first);
-      #amiStartMixMonitor(first,"{}/{}-{}-{}.wav".format(date.today().strftime("%Y/%m/%d"), msg.Exten, msg.CallerIDnum, msg.UniqueID));#2022/03/11/external-2534-1934-20220311-122726-1647001646.56557.wav
-      #amiStopMixMonitor(second);
+      firstname = extra['transferee_channel_name']
+      secondname = extra['channel2_name']
+      if (msg.CallerIDrdnis == '78124254209'):
+        res = await amiStopMixMonitor(firstname);
+        app.logger.warning('{}'.format(res))
+        filename = "transfer-{}-{}-{}.wav".format(msg.Exten, msg.CallerIDnum, msg.LinkedID);
+        res = await amiStartMixMonitor(firstname,"{}/{}".format(date.today().strftime("%Y/%m/%d"),filename));#2022/03/11/external-2534-1934-20220311-122726-1647001646.56557.wav
+        res = await amiChannelSetVar(firstname,"CDR(recordingfile)",filename)
+        app.logger.warning('{}'.format(res));
+        #await amiStopMixMonitor(secondname);
       app.cache['cel_calls'][lid]['transfers'].append((first,second)) #no cdr in db here
       app.logger.warning('first {} {}'.format(first,second))
     
@@ -606,6 +615,30 @@ async def amiUserEvent(name, data):
       return reply.message
   return 'AMI error'
 
+async def amiChannelSetVar(channel,variable, value):
+  '''AMI SetVar
+  Sets variable using AMI action SetVar to value in background.
+
+  Parameters:
+    channel (string)
+    variable (string): Variable to set
+    value (string): Value to set for variable
+
+  Returns:
+    string: None if SetVar was successfull, error message overwise
+  '''
+  reply = await manager.send_action({'Action': 'SetVar',
+                                     'Variable': variable,
+                                     'Channel': channel,
+                                     'Value': value})
+  app.logger.warning('SetVar({},{}={})'.format(channel,variable, value))
+  if isinstance(reply, Message):
+    if reply.success:
+      return None
+    else:
+      return reply.message
+  return 'AMI error'
+
 async def amiSetVar(variable, value):
   '''AMI SetVar
   Sets variable using AMI action SetVar to value in background.