Genesys Cloud - Main

 View Only


Discussion Thread View
  • 1.  Nested Array Translation Map Issue - Conversation Details

    Posted 3 days ago
    Edited by Matt Riedl 3 days ago

    Hello,

    I am currently trying to extract a couple elements from the conversation details API:

    /api/v2/analytics/conversations/${input.conversationId}/details

    One of the elements I need is within a nested array, and I've been trying to use a translation map to extract the relevant elements:

    Output Contract:

    {
      "type": "object",
      "properties": {
        "participants": {
          "type": "array",
          "items": {
            "title": "agentParticipantObject",
            "type": "object",
            "properties": {
              "participantId": {
                "type": "string"
              },
              "sessions": {
                "type": "array",
                "items": {
                  "title": "agentSessionObject",
                  "type": "object",
                  "properties": {
                    "sessionId": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": true
                }
              }
            },
            "additionalProperties": true
          }
        }
      },
      "additionalProperties": true
    }

    Translation map:

     {
      "translationMap": {
        "agentParticipantId": "$.participants[*].participantId",
        "agentSessionId": "$.participants[*].sessions[*].sessionId"
      },
      "translationMapDefaults": {},
      "successTemplate": "{\"agentParticipantId\": ${successTemplateUtils.firstFromArray(\"${agentParticipantId}\",\"0\")},\"agentSessionId\": ${successTemplateUtils.firstFromArray(\"${agentSessionId}\",\"0\")} }"
    }

    Result:

    It seems like I am most of the way there, but I am having a difficult time removing the participants and sessions arrays from the output.  I was hoping someone could point me in the right direction.

    In the end my goal is to use this API to extract the elements I need to execute this API in order to set a wrap-up code in a trigger/workflow configuration: 

    /api/v2/conversations/messages/{conversationId}/participants/{participantId}/communications/{communicationId}/wrapup 

    Thanks,

    Matt


    #ArchitectureandDesign
    #Integrations

    ------------------------------
    Matt Riedl
    Acliviti, LLC
    ------------------------------



  • 2.  RE: Nested Array Translation Map Issue - Conversation Details
    Best Answer

    Top 25 Contributor
    Posted 2 days ago

    Update your output contract to just be:

    {
      "type": "object",
      "properties": {
        "participantId": {
          "type": "string"
        },
        "sessionId": {
          "type": "string"
        }
      },
      "additionalProperties": true
    }

    with the translationmap as:

     {
      "translationMap": {
        "participantId": "$.participants[*].participantId",
        "sessionId": "$.participants[*].sessions[*].sessionId"
      },
      "translationMapDefaults": {},
      "successTemplate": "{\"participantId\": ${successTemplateUtils.firstFromArray(\"${participantId}\",\"0\")},\"sessionId\": ${successTemplateUtils.firstFromArray(\"${sessionId}\",\"0\")} }"
    }

    And it should work.

    The next issue you will face however is that the result is not the agent participant id, but just the very first one, which for inbound is likely to be the customer.

    So you are going to want to apply a filter eg

    $.participants[?(@.purpose == 'agent')].participantId or customer or acd or whatever participant you are looking for. And then you might need to further differentiate if you might have multiple agents on the call. 

    And for session, similar $.participants[?(@.purpose == 'agent')].sessions[0].sessionId I just added 0 to get the first session, but again you could do a filter or do -1 for the last item in the array etc. 

    I believe you can also use 

    PATCH /api/v2/conversations/{conversationId}/participants/{participantId} to apply a wrap up to the participant without worrying about the session.
    - Though not 100% on this approach.


    ------------------------------
    Anton Vroon
    ------------------------------



  • 3.  RE: Nested Array Translation Map Issue - Conversation Details

    Posted 2 days ago

    Thanks Anton!

    This is exactly what I needed.



    ------------------------------
    Matt Riedl
    Acliviti, LLC
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources