Genesys Cloud - Main

 View Only


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

    Posted 4 days ago
    Edited by Matt Riedl 4 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
    ------------------------------



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

    Posted yesterday

    Hey Anton!

    I didn't know about the successTemplateUtils.firstFromArray thing. I have a similar requirement and have been returning an array and processing it in Architect! This will streamline things tremendously.

    Thanks!



    ------------------------------
    Paul Simpson
    Views expressed are my own and do not necessarily reflect those of my employer.
    ------------------------------



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

    Top 25 Contributor
    Posted 23 hours ago

    If there is one thing I found really lacking as far as training material, it is the DataAction outputs, translation mappings, and velocity macros like that.

    All the material out there are usually basic outputs and just uses raw results.

    A lot of time spent on the developer forum figuring out things like that from past threads.

    I would love to see a Q&A or a DevBlog/DevCast or anything really going over how to write the mapping and some common velocity macros and how to use them.  



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



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

    Posted 23 hours ago

    Anton,

    You won't get any argument from me there! I often see it heavily implied, if not outright stated, that it is following some well-known standard library, I believe for JavaScript. If that is true, then if anyone knows the name of that library, we could perhaps find external documentation! 😁



    ------------------------------
    Paul Simpson
    Views expressed are my own and do not necessarily reflect those of my employer.
    ------------------------------



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

    Posted 22 hours ago

    Of course, as soon as I hit "Post", I tried Googling the function name, successTemplateUtils.firstFromArray, and found this.

    HTH



    ------------------------------
    Paul Simpson
    Views expressed are my own and do not necessarily reflect those of my employer.
    ------------------------------



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

    Top 25 Contributor
    Posted 22 hours ago

    That is a very large resource page. Even so, really would like a video or webinar or a blog or something that breaks it down and explains it step by step with some real examples with Genesys APIs that an admin can replicate.



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



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

    Posted 13 hours ago

    Thanks, that is helpful!



    ------------------------------
    Christoph Domaschke
    CRONBANK AG
    ------------------------------



Need Help finding something?

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