def end(self, id, timestamp):

        call = Call.objects.update_or_create(ucid=id)[0]
        call.end = timestamp
        call.state = "ended"

        agents = Agent.objects.filter(ext=call.origin)
        for agent in agents:
            agent.current_call = None

        agents = Agent.objects.filter(ext=call.destination)
        for agent in agents:
            agent.current_call = None

        agents = Agent.objects.filter(current_call=call)
        if len(agents) > 0:
            for agent in agents:
                redis = Redis().update('call', 'endcall', id,
                                       agent.phone_login)
                agent.current_call = None
                agent.save()

        call.save()

        ot_api_event().updateEndDate(call)
        return True
 def update_details(self, id, timestamp, data):
     redis = Redis().update('call', 'calltype', id, data)
     call = Call.objects.get_or_create(ucid=id)[0]
     call.call_type = data
     call.save()
     ot_api_event().updateEventType(call)
     Redis().update('call', 'calltype', id, data)
     return True
    def set_caller(self, id, timestamp, data):
        redis = Redis().update('call', 'phonenumber', id, data)
        call = Call.objects.get_or_create(ucid=id)[0]

        if call.origin == None:
            try:
                agent = Agent.objects.get(data)
            except:
                call.origin = data
                call.save()
                ot_api_event().updateEventPhoneNumber(call)
        return True
    def transfer_call(self, id, timestamp, destination):

        call = Call.objects.get_or_create(ucid=id)[0]

        agents_orig = Agent.objects.filter(current_call=call)
        for agent in agents_orig:
            agent.current_call = None
            agent.save()
            Redis().update('call', 'transferring', id, agent.phone_login)

        agents = Agent.objects.filter(ext=destination)
        if len(agents) > 0:
            if agents[0].isQueueLine:
                if call.isContactCenterCall == False:
                    self.centrale(id, timestamp, destination)

        transfers = call.getTransfers().filter(ttimestamp=timestamp,
                                               tdestination=destination)
        # check if this exists already
        if len(transfers) == 0:
            torigin = call.destination
            if torigin != destination:
                t = Transfer(call=call,
                             torigin=torigin,
                             tdestination=destination,
                             ttimestamp=timestamp)
                t.save()

        call.updatehistory()
        call.destination = destination
        call.save()

        agents = Agent.objects.filter(ext=destination)
        #redis = Redis().update('call', 'transfer', id, destination)
        if len(agents) == 1:
            agent = agents[0]
            agent.current_call = call
            agent.save()
            ot_api_event().transfer(call, agent)
            redis = Redis().update('call', 'transfer', id, agent.phone_login)
        else:
            log.error("no agents found with ext %s" % destination)
            # ot_api_event().transfer(call)

        return True
    def centrale(self, id, timestamp, ext):
        log.info("Call in IVR,%s" % ext)
        call = Call.objects.get_or_create(ucid=id)[0]
        call.start = timestamp
        call.destination = ext
        call.isContactCenterCall = True
        call.save()

        centrale = Agent.objects.get_or_create(ext=ext)[0]
        centrale.isQueueLine = True
        centrale.firstname = "Centrale IVR"
        centrale.ot_userloginname = "Centrale"
        centrale.current_call = None
        centrale.save()
        centrale.current_call = call

        centrale.save()
        Redis().update('call', 'create', id, ext)

        return ot_api_event().create(call)
Esempio n. 6
0
import os
import logging
import redis
from eventmanager import services
import time
import django
from eventmanager import ot_api
from datetime import timedelta, datetime

os.environ['DJANGO_SETTINGS_MODULE'] = 'mydjango.settings'

django.setup()

b = redis.StrictRedis(host='redis', decode_responses=True, port=6379, db=2)
logging.warning("Connected to Redis, Database 2, port 6379")
ot = ot_api.ot_api_event()
ot.updateTickets()
batch = datetime.now()
d = timedelta(minutes=15)
logging.warning("Starting watching events")
while True:

    if batch - d > datetime.now():
        ot.updateTickets()
        batch = datetime.now()

    keys = b.keys('*')
    if len(keys) == 0:
        #easier on CPU usage
        time.sleep(0.1)
    for key in keys: