Example: email sorting and language detection
In this example, we'll analyze email messages arriving in a customer support inbox and transfer them to other email addresses if needed. This can be helpful to reroute, for example, sales leads, billing questions, and foreign language requests to the right team.
For this example, you'll need three event-driven integration configurations:
-
email AI analysis with additional custom instructions containing the email categories you want to use in the sorting
-
saving the email category for sorting, and setting the language of the email conversation based on the AI analysis
-
matching the email category with a destination queue and transferring the email if needed
Email AI analysis
Configure email AI analysis as instructed, with the following considerations:
-
Define the queue as the email queue where you're receiving the customer emails that need sorting.
-
Add a "block": true definition to your request in the JSON configuration. Read more about this definition in the Event-driven integrations document.
-
Add custom instructions containing the email categories you want to use in the sorting in the JSON configuration. For example:
"customAiInstructions": "Category: Identify from the email content and select exactly one of the following categories:\n- Sales and Growth - New Sales Inquiry\n- Sales and Growth - Account Expansion\n- Sales and Growth - Demo Booking\n- Customer Support - Technical Bug Reports\n- Customer Support - Product Guidance\n- Customer Support - Feature Requests\n- Customer Support - Service Outages\n- Billing and Finance - Invoices and Payments\n- Billing and Finance - Refund Requests\n- Billing and Finance - Vendor Setup\n- Account Administration - Login and Access\n- Account Administration - Account Updates\n- Account Administration - Service Cancellation\n- Legal and Privacy - Data Privacy\n- Legal and Privacy - Compliance and Security\n- Legal and Privacy - Contract Review\n- Partnerships and PR - Business Development\n- Partnerships and PR - Press and Media Inquiries\n- HR and Careers - Job Applications\n- HR and Careers - Employment Verification\n- Noise - Unsolicited Sales Pitches\n- Noise - Newsletters and Marketing\n- Noise - Automated System Alerts\n- Noise - Spam and Phishing\n\nIf none of these cases apply, default to Other - Unidentified."
Save category to contact attached data and set language
Add a configuration with the following details:
-
Endpoint URL: The URL of your Restful Contact Management Interface's (CMI) contacts/{contact.id}/aiAnalysis resource
-
Channel Type: Email
-
Events: Received
-
Queues: the email queue where you're receiving the customer emails that need sorting
-
JSON for configuration:
{ "request": { "method": "GET", "authentication": { "type": "basic", "secrets_ref": "cmi-email-analysis-user" }, "headers": { "x-api-key": "{secrets.ri-apikey}" } }, "response": { "save": { "Category": "{response.body.aiAnalysis.Category}" }, "set": { "language": "{response.body.aiAnalysis.Language}" } } }
Transferring email messages to other addresses if needed
Add a configuration with the following details:
-
Endpoint URL: edi://echo
-
Channel Type: Email
-
Events: Received
-
JSON for configuration:
{ "request": { "method": "POST", "condition": [ "transfer = False", "cad = contact.get_attached_data()", "category = str(cad.get('Category', ''))", "if category.startswith('Noise'):", [ "contact.update_attached_data(transfer_to='spam@standarddemo.sinch')", "transfer = True" ], "elif category.startswith('Sales'):", [ "contact.update_attached_data(transfer_to='sales@standarddemo.sinch')", "transfer = True" ], "elif category.startswith('Billing'):", [ "contact.update_attached_data(transfer_to='billing@standarddemo.sinch')", "transfer = True" ], "elif category.startswith('Account'):", [ "contact.update_attached_data(transfer_to='admin@standarddemo.sinch')", "transfer = True" ], "elif category.startswith('Legal'):", [ "contact.update_attached_data(transfer_to='legal@standarddemo.sinch')", "transfer = True" ], "elif category.startswith('Partnerships'):", [ "contact.update_attached_data(transfer_to='partners@standarddemo.sinch')", "transfer = True" ], "elif category.startswith('HR'):", [ "contact.update_attached_data(transfer_to='hr@standarddemo.sinch')", "transfer = True" ], "result = transfer" ], "body": { "address": "{contact.cad.transfer_to}" } }, "response": { "set": { "queue": { "address": "{response.body.content.address}" } } } }
Replace the category references (Noise, Sales, and so on) with your categories and the email addressses (spam@standarddemo.sinch, sales@standarddemo.sinch, and so on) with the addressses of your email queues.
