def create_workflow(workspace, queues): defaultRuleTarget = WorkflowRuleTarget(queues['default'].sid, '1==1', 1, 30) rules = [] queueRuleTargets = [] queueRuleTarget = WorkflowRuleTarget(queues['sms'].sid, None, 5, 30) queueRuleTargets.append(queueRuleTarget) queueRuleTargets.append(defaultRuleTarget) rules.append( WorkflowRule("selected_product==\"ProgrammableSMS\"", [queueRuleTarget, defaultRuleTarget], None)) queueRuleTargets = [] queueRuleTarget = WorkflowRuleTarget(queues['voice'].sid, None, 5, 30) queueRuleTargets.append(queueRuleTarget) queueRuleTargets.append(defaultRuleTarget) rules.append( WorkflowRule("selected_product==\"ProgrammableVoice\"", [queueRuleTarget, defaultRuleTarget], None)) config = WorkflowConfig(rules, defaultRuleTarget) callback_url = HOST + '/assignment' return CLIENT.workflows(workspace.sid).create( friendly_name='Sales', assignment_callback_url=callback_url, fallback_assignment_callback_url=callback_url, task_reservation_timeout=15, configuration=config.to_json())
def test_to_json(self): rules = [ WorkflowRule("1==1", [WorkflowRuleTarget("WQeae4fc2f4db7f377c5d3758fb08b79b7", "1==1", 1, 20)], "SomeQ"), WorkflowRule("1==1", [WorkflowRuleTarget("WQ19ebe92fb33522f018b5a31d805d94da", "1==1", 1, 210)], "SomeOtherQ") ] def_target = WorkflowRuleTarget("WQ9963154bf3122d0a0558f3763951d916", "1==1", None, None) config = WorkflowConfig(rules, def_target) self.assertEqual(True, self.is_json(config.to_json()))
def test_to_json(self): rules = [ WorkflowRule("1==1", [ WorkflowRuleTarget("WQeae4fc2f4db7f377c5d3758fb08b79b7", "1==1", 1, 20) ], "SomeQ"), WorkflowRule("1==1", [ WorkflowRuleTarget("WQ19ebe92fb33522f018b5a31d805d94da", "1==1", 1, 210) ], "SomeOtherQ") ] def_target = WorkflowRuleTarget("WQ9963154bf3122d0a0558f3763951d916", "1==1", None, None) config = WorkflowConfig(rules, def_target) self.assertEqual(True, self.is_json(config.to_json()))
def test_from_json2(self): data = {'task_routing': {'filters': [{'friendly_name': 'SomeQ', 'expression': '1==1', 'targets': [ {'priority': 1, 'queue': 'WQXXXX', 'expression': '1==1', 'timeout': 20}]}, {'friendly_name': 'SomeOtherQ', 'expression': '1==1', 'targets': [ {'priority': 1, 'queue': 'WQXXXX', 'expression': '1==1', 'timeout': 20}]}], 'default_filter': {'priority': None, 'queue': 'WQYYYYY', 'expression': None, 'timeout': None}}} config = WorkflowConfig.json2obj(json.dumps(data)) self.assertEqual(2, len(config.task_routing.filters)) self.assertEqual(4, len(config.task_routing.default_filter))
def test_from_json(self): data = { 'task_routing': { 'filters': [ { 'expression': 'type == "sales"', 'friendly_name': 'Sales', 'targets': [ { 'queue': 'WQec62de0e1148b8477f2e24579779c8b1', 'expression': 'task.language IN worker.languages' } ] }, { 'expression': 'type == "marketing"', 'friendly_name': 'Marketing', 'targets': [ { 'queue': 'WQ2acd4c1a41ffadce5d1bac9e1ce2fa9f', 'expression': 'task.language IN worker.languages' } ] }, { 'expression': 'type == "support"', 'friendly_name': 'Support', 'targets': [ { 'queue': 'WQe5eb317eb23500ade45087ea6522896c', 'expression': 'task.language IN worker.languages' } ] } ], 'default_filter': { 'queue': 'WQ05f810d2d130344fd56e3c91ece2e594' } } } config = WorkflowConfig.json2obj(json.dumps(data)) self.assertEqual(3, len(config.task_routing.filters)) self.assertEqual(1, len(config.task_routing.default_filter))
def test_from_json(self): data = { 'task_routing': { 'filters': [{ 'expression': 'type == "sales"', 'friendly_name': 'Sales', 'targets': [{ 'queue': 'WQec62de0e1148b8477f2e24579779c8b1', 'expression': 'task.language IN worker.languages' }] }, { 'expression': 'type == "marketing"', 'friendly_name': 'Marketing', 'targets': [{ 'queue': 'WQ2acd4c1a41ffadce5d1bac9e1ce2fa9f', 'expression': 'task.language IN worker.languages' }] }, { 'expression': 'type == "support"', 'friendly_name': 'Support', 'targets': [{ 'queue': 'WQe5eb317eb23500ade45087ea6522896c', 'expression': 'task.language IN worker.languages' }] }], 'default_filter': { 'queue': 'WQ05f810d2d130344fd56e3c91ece2e594' } } } config = WorkflowConfig.json2obj(json.dumps(data)) self.assertEqual(3, len(config.task_routing.filters)) self.assertEqual(1, len(config.task_routing.default_filter))
def test_from_json2(self): data = { 'task_routing': { 'filters': [{ 'friendly_name': 'SomeQ', 'expression': '1==1', 'targets': [{ 'priority': 1, 'queue': 'WQXXXX', 'expression': '1==1', 'timeout': 20 }] }, { 'friendly_name': 'SomeOtherQ', 'expression': '1==1', 'targets': [{ 'priority': 1, 'queue': 'WQXXXX', 'expression': '1==1', 'timeout': 20 }] }], 'default_filter': { 'priority': None, 'queue': 'WQYYYYY', 'expression': None, 'timeout': None } } } config = WorkflowConfig.json2obj(json.dumps(data)) self.assertEqual(2, len(config.task_routing.filters)) self.assertEqual(4, len(config.task_routing.default_filter))
salesRuleTargets = [] salesRuleTarget = WorkflowRuleTarget(sales_queue_sid, None, None, None) salesRuleTargets.append(salesRuleTarget) salesRule = WorkflowRule("type=='sales'", salesRuleTargets, None) marketingRuleTargets = [] marketingRuleTarget = WorkflowRuleTarget(marketing_queue_sid, None, None, None) marketingRuleTargets.append(marketingRuleTarget) marketingRule = WorkflowRule("type=='marketing'", marketingRuleTargets, None) supportRuleTargets = [] supportRuleTarget = WorkflowRuleTarget(support_queue_sid, None, None, None) supportRuleTargets.append(supportRuleTarget) supportRule = WorkflowRule("type=='support'", supportRuleTargets, None) rules.append(salesRule) rules.append(marketingRule) rules.append(supportRule) defaultTarget = WorkflowRuleTarget(everyone_queue_sid, None, None, None) config = WorkflowConfig(rules, defaultTarget) json = config.to_json() workflow = client.workflows(workspace_sid).create( friendly_name='Sales, Marketing, Support Workflow', assignment_callback_url='http://example.com', fallback_assignment_callback_url='http://example2.com', task_reservation_timeout='30', configuration=json) print(workflow.friendly_name)
def test_from_json_with_filter_friendly_name(self): data = { 'task_routing': { 'filters': [ { 'expression': 'type == "sales"', 'filter_friendly_name': 'Sales', 'targets': [ { 'queue': 'WQec62de0e1148b8477f2e24579779c8b1', 'expression': 'task.language IN worker.languages' } ] }, { 'expression': 'type == "marketing"', 'filter_friendly_name': 'Marketing', 'targets': [ { 'queue': 'WQ2acd4c1a41ffadce5d1bac9e1ce2fa9f', 'expression': 'task.language IN worker.languages' } ] }, { 'expression': 'type == "support"', 'filter_friendly_name': 'Support', 'targets': [ { 'queue': 'WQe5eb317eb23500ade45087ea6522896c', 'expression': 'task.language IN worker.languages' } ] } ], 'default_filter': { 'queue': 'WQ05f810d2d130344fd56e3c91ece2e594' } } } # marshal object config = WorkflowConfig.json2obj(json.dumps(data)) self.assertEqual(3, len(config.task_routing.filters)) self.assertEqual(1, len(config.task_routing.default_filter)) # check that the configuration was marshaled to "friendly_name" and not "filter_friendly_name" expected_config_data = { "task_routing": { "default_filter": { "queue": "WQ05f810d2d130344fd56e3c91ece2e594" }, "filters": [ { "expression": "type == \"sales\"", "friendly_name": "Sales", "targets": [ { "expression": "task.language IN worker.languages", "queue": "WQec62de0e1148b8477f2e24579779c8b1" } ] }, { "expression": "type == \"marketing\"", "friendly_name": "Marketing", "targets": [ { "expression": "task.language IN worker.languages", "queue": "WQ2acd4c1a41ffadce5d1bac9e1ce2fa9f" } ] }, { "expression": "type == \"support\"", "friendly_name": "Support", "targets": [ { "expression": "task.language IN worker.languages", "queue": "WQe5eb317eb23500ade45087ea6522896c" } ] } ] } } expected_config_json = json.dumps(expected_config_data, sort_keys=True, indent=4) # check that marshaling back stays as "friendly_name" self.assertEqual(config.to_json(), expected_config_json)
salesRuleTargets.append(salesRuleTarget) salesRule = WorkflowRule("type=='sales'", salesRuleTargets, None) marketingRuleTargets = [] marketingRuleTarget = WorkflowRuleTarget(marketing_queue_sid, None, None, None) marketingRuleTargets.append(marketingRuleTarget) marketingRule = WorkflowRule("type=='marketing'", marketingRuleTargets, None) supportRuleTargets = [] supportRuleTarget = WorkflowRuleTarget(support_queue_sid, None, None, None) supportRuleTargets.append(supportRuleTarget) supportRule = WorkflowRule("type=='support'", supportRuleTargets, None) rules.append(salesRule) rules.append(marketingRule) rules.append(supportRule) defaultTarget = WorkflowRuleTarget(everyone_queue_sid, None, None, None) config = WorkflowConfig(rules, defaultTarget) json = config.to_json() workflow = client.workflows(workspace_sid).create( friendly_name='Sales, Marketing, Support Workflow', assignment_callback_url='http://example.com', fallback_assignment_callback_url='http://example2.com', task_reservation_timeout='30', configuration=json ) print(workflow.friendly_name)