Translate Data Action Response

Hi all,

I am not sure if what I am trying to do is even possible, but here goes.
Trying to Flatten the output of the below Data Action to pass Array of messageText in the messagingTranscript data into architect.

Data Action:
/api/v2/conversations/${input.conversationId}/recordings

Contracts:

Input:
{
  "type": "object",
  "properties": {
    "conversationId": {
      "type": "string"
    }
  },
  "additionalProperties": true
}

Output:

{
  "title": "Recordings",
  "type": "array",
  "items": {
    "title": "Recording",
    "type": "object",
    "properties": {
      "messagingTranscript": {
        "type": "array",
        "items": {
          "title": "message",
          "type": "object",
          "properties": {
            "messageText": {
              "type": "string"
            }
          },
          "additionalProperties": true
        }
      }
    },
    "additionalProperties": true
  }
}

Response:

{
  "translationMap": {"Message": "$..messagingTranscript[*].messageText"},
  "translationMapDefaults": {},
  "successTemplate": "{\"Transcript\" : $Message}"
}

If I change successTemplate to rawResult it shows as this, but it cannot be flattened.

Is it possible to accomplish what I am trying to do?
If yes, then Please help me understand how to translate the data for use.

Any links to guides on translation mapping are welcome.

You were almost there!

Your output contract was still configured to look like the response you were getting from the endpoint. Since you used a translation map to pull out the part that you wanted, you needed to update the output contract to match.

Something like this is probably what you are looking for:

{
  "title": "Transcript",
  "type": "object",
  "properties": {
    "Transcript": {
      "type": "array",
      "items": {
        "title": "messageText",
        "type": "string"
      }
    }
  },
  "additionalProperties": true
}

--Jason

1 Like

Thanks Jason, can't believe i was so close :slight_smile:

Last question,
How would i build an object, MessageO, to hold the purpose and messageText?

Translation: (here i dont know how to build the Object)

{
  "translationMap": {
    "Message": "$..messagingTranscript[*].messageText",    
    "Purpose": "$..messagingTranscript[*].purpose",
    "MessageO": "$Purpose $Message"
  },
  "translationMapDefaults": {},
  "successTemplate": "{\"Transcript\" : $MessageO}"
}

Contract:

{
  "title": "Transcript",
  "type": "object",
  "properties": {
    "Transcript": {
      "type": "array",
      "items": {
        "title": "MessageO",
        "type": "object",
        "properties": {
          "purpose": {
            "type": "string"
          },
          "messageText": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    }
  },
  "additionalProperties": true
}

Hi Jason,

I have been trying everything but I can't seem to get all the components aligned to produce an array of objects containing purpose and messageText in the object.

Is it even possible?

After taking a couple of cracks at this, all i have been able to come up with that might be useful is that you could swap out
"Message": "$..messagingTranscript[*].messageText",
with something like
"combo": "$..messagingTranscript[*]['messageText', 'purpose']",

which would return an array of objects with the messageText and purpose name/value pairs. At that point you might have to pass that object back to architect and iterate through it there, or maybe we can come up with some string replacement that would get you what you want.

Could you provide an example of the input you expect and exactly what you want the output to be? The input doesn't need to be "real" data, but it does need to have the shape of the expected input and be valid json.

--Jason

1 Like

Hi Jason,

Sample JSON:

{
  "id": "7c63e9c4-c841-4971-82c9-fa4d42c9b419",
  "conversationId": "4667c3de-87da-4cc0-b33f-d39cf7489a1b",
  "startTime": "2024-01-30T07:03:37.444Z",
  "endTime": "2024-01-30T08:57:41.391Z",
  "media": "message",
  "annotations": [],
  "messagingTranscript": [
    {
      "from": "7b646d9c-fe8d-41df-aff8-5a20e478a7b0",
      "fromExternalContact": {
        "id": "74a557aa-ff41-4209-931a-7a8f025f032a",
        "modifyDate": "2024-01-30T07:03:37Z",
        "createDate": "2024-01-30T07:03:37Z",
        "selfUri": "/api/v2/externalcontacts/contacts/74a557aa-ff41-4209-931a-7a8f025f032a"
      },
      "to": "b18c1163-d342-4072-b2ae-b84079bbc326",
      "timestamp": "2024-01-30T07:03:36.890Z",
      "id": "ec32a0748e61a3e084f862a3e42ff52b",
      "purpose": "customer",
      "participantId": "0fefc503-0f9b-4a5b-817f-e25be2d7f304",
      "queue": {
        "id": "1689f212-8c27-4c47-9c70-eb1b24616851",
        "selfUri": "/api/v2/routing/queues/1689f212-8c27-4c47-9c70-eb1b24616851"
      },
      "events": [
        {
          "eventType": "Presence",
          "presence": {
            "type": "Join"
          }
        }
      ]
    },
    {
      "from": "b18c1163-d342-4072-b2ae-b84079bbc326",
      "to": "7b646d9c-fe8d-41df-aff8-5a20e478a7b0",
      "timestamp": "2024-01-30T07:03:37.938Z",
      "id": "720f929f77868291a15066907aaf3098",
      "purpose": "workflow",
      "participantId": "6760b165-b7a2-4564-867c-b511ac25d502",
      "workflow": {
        "id": "c3d28ea7-71c0-4c17-ae27-00f71fd5654c",
        "selfUri": "/api/v2/flows/c3d28ea7-71c0-4c17-ae27-00f71fd5654c"
      },
      "messageText": "Hi There, an Agent will be with you soon"
    },
    {
      "from": "b18c1163-d342-4072-b2ae-b84079bbc326",
      "fromUser": {
        "id": "328ffebb-076b-4068-9bab-f1ded1771628",
        "name": "Dewald Smit",
        "username": "dewald.smit@altron.com",
        "images": [
          {
            "resolution": "x96",
            "imageUri": "https://prod-euw1-inin-directory-service-profile.s3-eu-west-1.amazonaws.com/a63f424e/a7f1/4c74/b9c2/d6e402a71ac2.jpg"
          },
          {
            "resolution": "x128",
            "imageUri": "https://prod-euw1-inin-directory-service-profile.s3-eu-west-1.amazonaws.com/3bf216bf/7ca0/4877/ad39/28e0a551caf4.jpg"
          },
          {
            "resolution": "x200",
            "imageUri": "https://prod-euw1-inin-directory-service-profile.s3-eu-west-1.amazonaws.com/ad8161a5/21ff/497a/8409/d559fb12186c.jpg"
          },
          {
            "resolution": "x48",
            "imageUri": "https://prod-euw1-inin-directory-service-profile.s3-eu-west-1.amazonaws.com/68a8f90d/2c61/4830/96a4/78088a7b71e6.jpg"
          },
          {
            "resolution": "x300",
            "imageUri": "https://prod-euw1-inin-directory-service-profile.s3-eu-west-1.amazonaws.com/74244a87/112a/414e/a401/241994e93a4b.jpg"
          },
          {
            "resolution": "x400",
            "imageUri": "https://prod-euw1-inin-directory-service-profile.s3-eu-west-1.amazonaws.com/548dc779/2be6/4798/865d/222f7dac76fa.jpg"
          }
        ],
        "selfUri": "/api/v2/users/328ffebb-076b-4068-9bab-f1ded1771628"
      },
      "to": "7b646d9c-fe8d-41df-aff8-5a20e478a7b0",
      "timestamp": "2024-01-30T08:57:41.401Z",
      "id": "908e0e35025dbfd5bacd2bccc09aabd7",
      "purpose": "agent",
      "participantId": "fb648416-c1a5-4e88-912c-9c9cd2bdab3d",
      "queue": {
        "id": "1689f212-8c27-4c47-9c70-eb1b24616851",
        "selfUri": "/api/v2/routing/queues/1689f212-8c27-4c47-9c70-eb1b24616851"
      },
      "events": [
        {
          "eventType": "Presence",
          "presence": {
            "type": "Disconnect"
          }
        }
      ]
    }
  ],

What I would like to achieve in a workflow, is to send an agentless email with the messageText and purpose, aka Message Transcript, in the email body.
Build the email body from the array of objects.

Based on the example JSON that you provided, what exactly would you like the output from the data action to be?

The first and third objects in the messagingTranscript transcript do not have any messageText, so the JsonPath that I provided you in my previous comment comes back like this:

[
	{
		"purpose": "customer"
	},
	{
		"messageText": "Hi There, an Agent will be with you soon",
		"purpose": "workflow"
	},
	{
		"purpose": "agent"
	}
]

FYI, the </> button is the best option to format your JSON examples.

--Jason

Hi Jason,

Yes that is perfect, its the cleanest mock data I could quickly use.
I have managed to implement your changes on the Data action and i do get the Array of objects now, just in the process of getting our agentless email domain sorted on our Org so I can test the output on email body in a Flow.

Aiming to get this resolved in the next 2 weeks.

Thank you for all your wisdom. :slight_smile:

@Jason_Mathison, Just an update, been struggling with the workflow, also lack of time, and i found this gem blueprint "hidden" on github:
Send message transcript by email

The Blueprint URL on the Github is broken (the Genesys URL does not exist, guessing the page is still on the way).

Thanks @AgnesCorpuz , keep up the good work helping the community with the Blueprints that you do. :slight_smile:

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.