File: //home/arjun/projects/buyercall/buyercall/blueprints/workflows/utils/action_manager.py
import uuid
from flask import current_app
from buyercall.blueprints.agents.models import Team
from buyercall.blueprints.contacts.models import ContactTags
from buyercall.blueprints.email.models import EmailTemplate
from buyercall.extensions import ses_client
class ActionManager:
def run(self, contact, actions, data, **params):
print('actions found : ', actions)
for action in actions:
action_type = action.get('type')
if action_type == 'MAIL':
email_template = EmailTemplate.get_by_sid(action.get('template'))
ses_client.send_email([contact.email, ],
sender=current_app.congfig.get('MAIL_USERNAME', 'admin@buyercall.com'),
subject="New email message", html=email_template.content)
print('Sent mail to contact')
elif action_type == 'TAGS':
workflow_tags = action.get('tags')
workflow_tags = [uuid.UUID(wt) for wt in workflow_tags]
tags = ContactTags.query.filter(ContactTags.sid.in_(workflow_tags), ContactTags.is_active == True).all()
contact.contact_tags.extend(tags)
contact.save()
print('Assigned tag to contact')
elif action_type == 'AGENT':
# Assign contact to agents
agent_sids = [agent_id for agent_id in action.get('agentIds', []) if agent_id]
team_ids = action.get('teamIds', [])
for tid in team_ids:
team_agent_ids = Team.get_agent_sids_by_team_sid(tid)
agent_sids.extend(team_agent_ids)
contact.assign_agents(agent_sids=agent_sids)
print('Assigned contact to agents')
elif action_type == 'INTENT_SCORE':
pass
else:
pass
return