See related
No related articles

Move a generic email to correct customer's timeline

Last Update: Oct 2024 • Est. Read Time: 12 MIN
To check plan availability, see the pricing page.

If your team receives multiple emails from a specific email address and those emails should go to different customer profiles based on the content containing the customer’s email address, you can set up a Kustomer workflow to automatically move those conversations to the correct customer.

For instance, you receive multiple notification emails from an email address like noreply@provider-name.com about bookings from different customers that look like the below.

This article will walk you through the steps to create a workflow that will move those email conversations to the correct Customer object.

Who can access this feature?
User typesAdmins can access the Workflows and API Keys pages.


In this article

Prerequisites

Before following this guide, we recommend that you already be comfortable with the basics of using workflows.

We also recommend being familiar with creating API keys and adding workflow variables.

Create an API key

Create an API key by going to Settings  > Security > API Keys using the org.user.conversation.write and org.permission.conversation.update roles. Copy and save the token in a separate file for later use.

Create the workflow

Next, create a new workflow.

  1. Go to Settings > Platform > Workflows.
  2. Select Add Workflow. The New Workflow window opens.
  3. Enter a Workflow Title. You can leave the Description field blank because the code snippet below will provide this for you.
  4. Select Create to save the workflow and begin working in the Workflow Editor.

Enter the workflow JSON code

Use the Workflow Editor to paste in the workflow code supplied below. This JSON code will take care of most of the workflow creation, aside from a few placeholder values that you'll need to update manually.

  1. In the Workflow Editor, go to Workflow Options  and select Edit Workflow JSON.
  2. A window appears where you can edit the code for this workflow directly. Select and Delete the current JSON code.
  3. Copy the code block below, and paste it into the JSON text field in your Workflow Editor:
    {
      "description": "This workflow will move conversations from a generic email address to their appropriate customer timelines",
      "name": "move-generic-emails-workflow",
      "steps": [
        {
          "transitions": [
            {
              "target": "Dy3rji789",
              "condition": {
                "op": "true",
                "values": [
                  true
                ]
              }
            }
          ],
          "errorCases": [],
          "id": "e9Q4xexax",
          "appVersion": "kustomer-^1.5.3"
        },
        {
          "transitions": [
            {
              "target": "xJOlOMnuz",
              "condition": {
                "op": "true",
                "values": [
                  true
                ]
              }
            }
          ],
          "errorCases": [],
          "id": "Dy3rji789"
        },
        {
          "transitions": [
            {
              "target": "aL8VV0VbX",
              "condition": {
                "op": "exists",
                "values": [
                  "/#steps.xJOlOMnuz.match",
                  ""
                ]
              },
              "meta": {
                "name": "Email Address Found in Body"
              }
            }
          ],
          "errorCases": [],
          "id": "xJOlOMnuz",
          "action": "kustomer.regex-match.generic",
          "params": {
            "regex": "([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+)",
            "testString": "/#steps.1.body"
          },
          "appVersion": "kustomer-^1.9.2",
          "meta": {
            "displayName": "Find Email Match in Message Body"
          }
        },
        {
          "transitions": [
            {
              "target": "2Re5lqKh-",
              "condition": {
                "op": "exists",
                "values": [
                  "/#steps.aL8VV0VbX.id",
                  ""
                ]
              },
              "meta": {
                "name": "Email Message is Found"
              }
            }
          ],
          "errorCases": [],
          "id": "aL8VV0VbX",
          "action": "kustomer.message.find-by-id",
          "params": {
            "id": "/#steps.1.id"
          },
          "appVersion": "kustomer-^1.9.2",
          "meta": {
            "displayName": "Find Email Message in Kustomer"
          }
        },
        {
          "transitions": [
            {
              "target": "TOUPj-zBx",
              "condition": {
                "op": "true",
                "values": [
                  true
                ]
              }
            }
          ],
          "errorCases": [],
          "id": "2Re5lqKh-"
        },
        {
          "transitions": [
            {
              "target": "71igq5x_v",
              "condition": {
                "op": "true",
                "values": [
                  true
                ]
              },
              "meta": {
                "name": "stop"
              }
            }
          ],
          "errorCases": [],
          "id": "TOUPj-zBx",
          "action": "kustomer.customer.find-by-email",
          "params": {
            "email": "/#steps.xJOlOMnuz.match"
          },
          "appVersion": "kustomer-^1.9.2",
          "meta": {
            "displayName": "Find Customer by Email"
          }
        },
        {
          "transitions": [
            {
              "target": "f-rngyCEV",
              "condition": {
                "op": "exists",
                "values": [
                  "/#steps.TOUPj-zBx.id",
                  ""
                ]
              },
              "meta": {
                "name": "Customer Found by Email"
              }
            },
            {
              "target": "0xs6Bk29L",
              "condition": {
                "op": "exists",
                "values": [
                  "true",
                  ""
                ]
              },
              "meta": {
                "name": "Customer does not Exist"
              }
            }
          ],
          "errorCases": [],
          "id": "71igq5x_v"
        },
        {
          "transitions": [
            {
              "target": "G2spIjO8X",
              "condition": {
                "op": "true",
                "values": [
                  true
                ]
              }
            }
          ],
          "errorCases": [],
          "id": "f-rngyCEV"
        },
        {
          "transitions": [],
          "errorCases": [],
          "id": "G2spIjO8X",
          "action": "kustomer.rest-api.json",
          "appVersion": "kustomer-^1.9.2",
          "params": {
            "method": "PUT",
            "json": true,
            "headers": {
              "content-type": "application/json",
              "Authorization": "Bearer"
            },
            "data": {
              "customer": "/#steps.TOUPj-zBx.id"
            },
            "uri": "https://api.kustomerapp.com/v1/conversations/{{{steps.aL8VV0VbX.conversation}}}"
          },
          "meta": {
            "displayName": "Move Conversation to Correct Customer"
          }
        },
        {
          "transitions": [
            {
              "target": "8J2fs1Oby",
              "condition": {
                "op": "true",
                "values": [
                  true
                ]
              }
            }
          ],
          "errorCases": [],
          "id": "1pIJ1EyKn",
          "appVersion": "kustomer-^1.5.3"
        },
        {
          "transitions": [
            {
              "target": "mS7UMku22",
              "condition": {
                "op": "true",
                "values": [
                  true
                ]
              }
            }
          ],
          "errorCases": [],
          "id": "0xs6Bk29L",
          "action": "kustomer.customer.create",
          "params": {
            "email": "/#steps.xJOlOMnuz.match"
          },
          "appVersion": "kustomer-^1.9.2",
          "meta": {
            "displayName": "Create New Customer"
          }
        },
        {
          "transitions": [],
          "errorCases": [],
          "id": "mS7UMku22",
          "action": "kustomer.rest-api.json",
          "params": {
            "method": "PUT",
            "json": true,
            "headers": {
              "content-type": "application/json",
              "Authorization": "Bearer"
            },
            "data": {
              "customer": "/#steps.0xs6Bk29L.id"
            },
            "uri": "https://api.kustomerapp.com/v1/conversations/{{{steps.aL8VV0VbX.conversation}}}"
          },
          "appVersion": "kustomer-^1.9.2",
          "meta": {
            "displayName": "Move Conversation to Correct Customer"
          }
        },
        {
          "transitions": [
            {
              "target": "e9Q4xexax",
              "condition": {
                "op": "eq",
                "values": [
                  "/#steps.1.fromEmail",
                  "test@test.com"
                ]
              },
              "meta": {
                "name": "Message from Specific Email Address"
              }
            }
          ],
          "errorCases": [],
          "id": "8J2fs1Oby",
          "appVersion": "kustomer-^1.5.3"
        }
      ],
      "trigger": {
        "transitions": [
          {
            "target": "1pIJ1EyKn",
            "condition": {
              "op": "true",
              "values": [
                true
              ]
            }
          }
        ],
        "eventName": "kustomer.app.postmark.message.receive",
        "id": "1",
        "appVersion": "postmark-^1.1.11",
        "meta": {
          "displayName": "Email Message Received"
        }
      }
    }
  4. Select Update to dismiss the JSON editor and save the changes to the workflow.

The workflow will look like the below.

Add the API key to the workflow

  1. In the Workflow Editor, go to Workflow Options  and select Workflow Variables.
  2. Add the saved token from the API key you created earlier as a workflow variable. Name the workflow variable as desired and add the token in the Value field.
  3. Save the variable, select Close to exit the workflow editor, and Save the updated workflow.

Customize the workflow

  1. In the first condition after the workflow trigger, customize the test email address to the email address(es) from where you receive multiple messages that should be moved to the correct customer timelines.
  2. In Steps 13 and 14 of the workflow, select the key icon in the REST API JSON action step to access the workflow variable saved, and copy the workflow variable.
  3. Add just one space after Bearer in the Headers section and paste the copied value which is the API token needed for authorization. The section should look like the below:
  4. If there are any other changes to the workflow that you'd like to make, you can do so now. When you're finished, Save all and other workflow changes.

When you're ready to activate this workflow, use the toggle to switch it on or off.

Workflow variations

You can change the workflow’s initial trigger to create or duplicate this automation for messages received from other channels besides email. You’ll then modify the workflow steps to account for the message content and specific data to look for within the Message Data to find the target Customer timeline and move the conversations correctly.