ADD DEV
This commit is contained in:
parent
9518a916a6
commit
285e2913f1
@ -48,15 +48,6 @@ services:
|
|||||||
- mongo
|
- mongo
|
||||||
networks:
|
networks:
|
||||||
- phone
|
- phone
|
||||||
worker-dev:
|
|
||||||
build: ./worker-dev
|
|
||||||
restart: always
|
|
||||||
environment:
|
|
||||||
- TZ=Asia/Krasnoyarsk
|
|
||||||
depends_on:
|
|
||||||
- mongo
|
|
||||||
networks:
|
|
||||||
- phone
|
|
||||||
web:
|
web:
|
||||||
build: ./web
|
build: ./web
|
||||||
restart: always
|
restart: always
|
||||||
@ -79,6 +70,27 @@ services:
|
|||||||
- phone
|
- phone
|
||||||
ports:
|
ports:
|
||||||
- 5002:5002
|
- 5002:5002
|
||||||
|
worker-dev:
|
||||||
|
build: ./worker-dev
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- TZ=Asia/Krasnoyarsk
|
||||||
|
depends_on:
|
||||||
|
- mongo
|
||||||
|
networks:
|
||||||
|
- phone
|
||||||
|
web-dev:
|
||||||
|
build: ./web-dev
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- TZ=Asia/Krasnoyarsk
|
||||||
|
depends_on:
|
||||||
|
- mongo
|
||||||
|
networks:
|
||||||
|
- phone
|
||||||
|
ports:
|
||||||
|
- 6001:6001
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
phone:
|
phone:
|
||||||
volumes:
|
volumes:
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -3,31 +3,102 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
|
||||||
import config
|
|
||||||
from pymongo import MongoClient
|
|
||||||
from msg import msg
|
|
||||||
import requests
|
import requests
|
||||||
import time
|
from pymongo import MongoClient
|
||||||
|
|
||||||
|
|
||||||
|
db_connection = MongoClient("mongodb://mongodb:Cc03Wz5XX3iI3uY3@mongo")
|
||||||
|
db_base = db_connection["phone-dev"]
|
||||||
|
coll_phone = db_base["phone"]
|
||||||
|
coll_userkey = db_base['userkey']
|
||||||
|
|
||||||
|
coll_phone.insert_one({"test": "Jopa"})
|
||||||
|
coll_userkey.insert_one({"test": "Jopa 2"})
|
||||||
|
# Stats:
|
||||||
|
# 0 - ответили
|
||||||
|
# 1 - не приняли
|
||||||
|
# 2 - перезвонили успешно
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(
|
connection = pika.BlockingConnection(pika.ConnectionParameters(
|
||||||
"192.168.0.20", 5672, "mkt", pika.PlainCredentials(
|
'rabbitmq', 5672, 'mkt', pika.PlainCredentials('rabbit', 'mrl2X0jwnYuCCiKFTshG7WKyOAhfDo')))
|
||||||
"rabbit", "mrl2X0jwnYuCCiKFTshG7WKyOAhfDo")
|
|
||||||
))
|
|
||||||
channel = connection.channel()
|
channel = connection.channel()
|
||||||
|
|
||||||
|
channel.queue_declare(queue='incoming-dev')
|
||||||
|
tmpIncoming = {}
|
||||||
|
# tmpExternal = {}
|
||||||
|
|
||||||
def callback(ch, method, properties, body: bytearray):
|
def callback(ch, method, properties, body: bytearray):
|
||||||
srcJson = json.loads(str(body.decode('utf-8')).replace("\'", "\""))
|
|
||||||
# if srcJson['state'] == 'HANGUP' and srcJson['direction'] == 'incoming' and srcJson['from'] == '89135853246':
|
|
||||||
try:
|
try:
|
||||||
if srcJson['callstatus'] != 'ANSWER':
|
# Парсим строку
|
||||||
print(srcJson)
|
srcJson = json.loads(str(body.decode('utf-8')).replace("\'", "\""))
|
||||||
except:
|
srcJson["time"] = datetime.datetime.fromtimestamp(
|
||||||
pass
|
srcJson["time"]).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
# Определяем направление соединения
|
||||||
|
if srcJson['direction'] == 'incoming':
|
||||||
|
# Определяем начальный статус
|
||||||
|
if srcJson['state'] == 'START':
|
||||||
|
# Создаем переменную. Ответ = false, можно закрывать = false, Приоритетная линия
|
||||||
|
if srcJson['to'] == '83912051045':
|
||||||
|
tmpIncoming[srcJson['uuid']] = [False, False, True]
|
||||||
|
else:
|
||||||
|
tmpIncoming[srcJson['uuid']] = [False, False, False]
|
||||||
|
# Обновление статуса при входящем звонке
|
||||||
|
coll_phone.delete_one({'$and': [{'client': srcJson['from']}, {'status': 1}]})
|
||||||
|
if srcJson['state'] == 'ANSWER' and srcJson['uuid'] in tmpIncoming:
|
||||||
|
tmpIncoming[srcJson['uuid']][0] = True
|
||||||
|
if srcJson['state'] == 'END' and srcJson['uuid'] in tmpIncoming:
|
||||||
|
tmpIncoming[srcJson['uuid']][1] = True
|
||||||
|
if srcJson['state'] == 'HANGUP' and srcJson['uuid'] in tmpIncoming and tmpIncoming[srcJson['uuid']][1] == True:
|
||||||
|
try:
|
||||||
|
srcJson['callstatus']
|
||||||
|
insDict = {"client": srcJson['from'], "time": srcJson['time'], "status": 0,
|
||||||
|
"recordUrl": srcJson["recordUrl"], "duration": srcJson["duration"], "important": tmpIncoming[srcJson['uuid']][2]}
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
insDict = {
|
||||||
|
"client": srcJson['from'], "time": srcJson['time'], "status": 1, "important": tmpIncoming[srcJson['uuid']][2], "uuid": srcJson['uuid']}
|
||||||
|
finally:
|
||||||
|
coll_phone.insert_one(insDict)
|
||||||
|
tmpIncoming.pop(srcJson['uuid'])
|
||||||
|
try:
|
||||||
|
insUserKey = {'userkey': srcJson['userkey']}
|
||||||
|
coll_userkey.update_one(
|
||||||
|
filter={
|
||||||
|
'operator': srcJson['to'],
|
||||||
|
},
|
||||||
|
update={
|
||||||
|
'$set': insUserKey,
|
||||||
|
},
|
||||||
|
upsert=True
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if srcJson['direction'] == 'external':
|
||||||
|
# coll_phone.update_one({'$and': [{'client': {'$regex': srcJson['to']}}, {'status': 1}}]}, {'$set': {'status': 2, 'callid': srcJson['uuid']}})
|
||||||
|
coll_phone.update_one({'$and': [{'client': {'$regex': srcJson['to']}}, {'status': 1}]}, {'$set': {'status': 2, 'callid': srcJson['uuid']}})
|
||||||
|
if srcJson['state'] == 'HANGUP':
|
||||||
|
try:
|
||||||
|
# Проверяем заполнено ли поле recordURL, если нет то меняем статус на 4
|
||||||
|
if len(srcJson['recordUrl']) > 4:
|
||||||
|
print(srcJson['uuid'], srcJson['recordUrl'])
|
||||||
|
coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'recordUrl': srcJson['recordUrl'], 'status': 2}})
|
||||||
|
else:
|
||||||
|
print(srcJson['uuid'])
|
||||||
|
coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'status': 4}})
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e.with_traceback)
|
||||||
|
print(e)
|
||||||
|
exit()
|
||||||
|
|
||||||
channel.basic_consume(
|
channel.basic_consume(
|
||||||
queue='copy_incoming', on_message_callback=callback, auto_ack=False)
|
queue='incoming-dev', on_message_callback=callback, auto_ack=False)
|
||||||
|
|
||||||
print(' [*] Waiting for messages. To exit press CTRL+C')
|
print(' [*] Waiting for messages. To exit press CTRL+C')
|
||||||
channel.start_consuming()
|
channel.start_consuming()
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
IMPORTANT_LINE = ['83912051045']
|
|
||||||
|
|
||||||
IGNORE_LIST = ['83912051045',
|
|
||||||
'83912051046',
|
|
||||||
'83919865589',
|
|
||||||
'83919865589',
|
|
||||||
'84950213944',
|
|
||||||
'84951183750',
|
|
||||||
'84951252791',
|
|
||||||
'89919237009',
|
|
||||||
'89919241441',
|
|
||||||
'89919398228',
|
|
||||||
'89919500798',
|
|
||||||
'89919505445',
|
|
||||||
'89919863883']
|
|
@ -5,7 +5,7 @@ RUN apk update && apk upgrade && apk add python3 && apk add -U tzdata
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
ADD *.py /app
|
ADD app.py /app
|
||||||
RUN python3 -m venv .venv
|
RUN python3 -m venv .venv
|
||||||
RUN /app/.venv/bin/pip3 install -r /app/requirements.txt
|
RUN /app/.venv/bin/pip3 install -r /app/requirements.txt
|
||||||
|
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
import pika
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import datetime
|
|
||||||
import re
|
|
||||||
import config
|
|
||||||
from pymongo import MongoClient
|
|
||||||
from msg import msg
|
|
||||||
import requests
|
|
||||||
import time
|
|
||||||
|
|
||||||
CONNECTION_STRING = "mongodb://mongodb:Cc03Wz5XX3iI3uY3@192.168.0.20"
|
|
||||||
db_connection = MongoClient(CONNECTION_STRING)
|
|
||||||
|
|
||||||
db_base = db_connection["phone"]
|
|
||||||
coll_call = db_base["phone_dev"]
|
|
||||||
from_api = db_base["from_api"]
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
connection = pika.BlockingConnection(pika.ConnectionParameters(
|
|
||||||
"192.168.0.20", 5672, "mkt", pika.PlainCredentials(
|
|
||||||
"rabbit", "mrl2X0jwnYuCCiKFTshG7WKyOAhfDo")
|
|
||||||
))
|
|
||||||
channel = connection.channel()
|
|
||||||
|
|
||||||
def callback(ch, method, properties, body: bytearray):
|
|
||||||
m = msg(body)
|
|
||||||
|
|
||||||
# Разбираем входящие звонки
|
|
||||||
if m.isIncoming():
|
|
||||||
# Если статус START
|
|
||||||
if m.getState() == "START":
|
|
||||||
insert_value = {
|
|
||||||
"uuid": m.getUUID(),
|
|
||||||
"status": -1,
|
|
||||||
"canClose": 0
|
|
||||||
}
|
|
||||||
|
|
||||||
coll_call.update_one(
|
|
||||||
filter={"client": m.getClient(), "status": -1},
|
|
||||||
update={"$set": insert_value},
|
|
||||||
upsert=True
|
|
||||||
)
|
|
||||||
#print("НАЧАТ:", m.dict)
|
|
||||||
|
|
||||||
# Если Статус END
|
|
||||||
if m.getState() == "END":
|
|
||||||
coll_call.update_one(
|
|
||||||
filter={"uuid": m.getUUID()},
|
|
||||||
update={"$set": {"canClose": 1}}
|
|
||||||
)
|
|
||||||
#print("ЗАКОНЧЕН:", m.dict)
|
|
||||||
time.sleep(5)
|
|
||||||
resp = requests.get("https://callinfo.services.mobilon.ru/api/call/info/1e86a98e026578eb5f6bf8c092c0c4a2/" + m.getUUID())
|
|
||||||
j = json.loads(resp.content.decode('utf-8'))
|
|
||||||
d = dict(j)
|
|
||||||
from_api.insert_one(d)
|
|
||||||
|
|
||||||
# Если статус HANGUP
|
|
||||||
if m.getState() == "HANGUP":
|
|
||||||
if m.isAnswered():
|
|
||||||
insert_value = {
|
|
||||||
"status": 0,
|
|
||||||
"duration": m.getDuration(),
|
|
||||||
"recordUrl": m.getRecordUrl()
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
insert_value = {
|
|
||||||
"status": 1
|
|
||||||
}
|
|
||||||
coll_call.update_one(
|
|
||||||
filter={"uuid": m.getUUID(), "canClose": 1},
|
|
||||||
update={"$set": insert_value}
|
|
||||||
)
|
|
||||||
#print("Положена трубка:", m.dict)
|
|
||||||
|
|
||||||
channel.basic_consume(
|
|
||||||
queue='test', on_message_callback=callback, auto_ack=True)
|
|
||||||
|
|
||||||
print(' [*] Waiting for messages. To exit press CTRL+C')
|
|
||||||
channel.start_consuming()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print('Interrupted')
|
|
||||||
try:
|
|
||||||
sys.exit(0)
|
|
||||||
except SystemExit:
|
|
||||||
os._exit(0)
|
|
@ -1,68 +0,0 @@
|
|||||||
import os
|
|
||||||
import json
|
|
||||||
import datetime
|
|
||||||
import re
|
|
||||||
import config
|
|
||||||
|
|
||||||
|
|
||||||
class msg:
|
|
||||||
def __init__(self, body):
|
|
||||||
self.body: bytearray = body
|
|
||||||
self.decode: str = self.body.decode('utf-8')
|
|
||||||
self.json: json = json.loads(self.decode.replace("\'", "\""))
|
|
||||||
self.dict: dict = dict(self.json)
|
|
||||||
|
|
||||||
def getDirection(self):
|
|
||||||
try:
|
|
||||||
return self.dict["direction"]
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def isIncoming(self) -> bool:
|
|
||||||
return True if self.dict["direction"] == "incoming" else False
|
|
||||||
|
|
||||||
def isExternal(self) -> bool:
|
|
||||||
return not self.isIncoming()
|
|
||||||
|
|
||||||
def getState(self) -> str:
|
|
||||||
try:
|
|
||||||
return self.dict["state"]
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def getClient(self) -> str:
|
|
||||||
return self.dict["from"] if self.isIncoming() else self.dict["to"]
|
|
||||||
|
|
||||||
def getTime(self) -> str:
|
|
||||||
try:
|
|
||||||
return datetime.datetime.fromtimestamp(self.dict["time"]).strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
except:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def getStatus(self) -> int:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def getRecordUrl(self) -> str:
|
|
||||||
return self.dict["recordUrl"]
|
|
||||||
|
|
||||||
def getDuration(self) -> int:
|
|
||||||
return self.dict["duration"]
|
|
||||||
|
|
||||||
def getUUID(self) -> str:
|
|
||||||
try:
|
|
||||||
return self.dict["uuid"]
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def isAnswered(self) -> bool:
|
|
||||||
try:
|
|
||||||
self.dict["callstatus"]
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def isImportant(self):
|
|
||||||
try:
|
|
||||||
return True if self.getState() == "START" and self.isIncoming() and self.dict["to"] in config.IMPORTANT_LINE else False
|
|
||||||
except:
|
|
||||||
pass
|
|
@ -12,15 +12,6 @@ db_base = db_connection["phone"]
|
|||||||
coll_phone = db_base["phone"]
|
coll_phone = db_base["phone"]
|
||||||
coll_userkey = db_base['userkey']
|
coll_userkey = db_base['userkey']
|
||||||
|
|
||||||
#def sendMessage(dt, num):
|
|
||||||
# token = "2035324623:AAGACtvZ551m9V--yTYF9cFuegGejylSsLg"
|
|
||||||
# chat_id = "-1001941363918"
|
|
||||||
# message = "*" + num + "* - " + dt
|
|
||||||
# send_text = 'https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + chat_id + '&parse_mode=Markdown&text=' + message
|
|
||||||
# response = requests.get(send_text)
|
|
||||||
# return response
|
|
||||||
|
|
||||||
|
|
||||||
# Stats:
|
# Stats:
|
||||||
# 0 - ответили
|
# 0 - ответили
|
||||||
# 1 - не приняли
|
# 1 - не приняли
|
||||||
|
Loading…
x
Reference in New Issue
Block a user