Legacy Dev Forum Posts

 View Only

Sign Up

  • 1.  Get Chat Transcript

    Posted 06-05-2025 18:17

    Lee_Canady | 2020-05-07 12:19:38 UTC | #1

    Hi,

    We are working on Recording APIs to get Chat transcripts for the conversations and send it to customers email. I'm not able to get chat messages alone from the APIs. It's coming along with other parameters. Even if I managed to get all the messages in a single array, I'm not able to separate agent messages and customer messages.

    Please help if there is a way to get the chat transcript in below format.

    Agent: Hi Agent: How can I help you? Customer: I have a query with one of you product.

    Thanks.


    Jerome.Saint-Marc | 2020-05-07 16:11:28 UTC | #2

    Hello,

    You will have to process the objects/messages in the "transcript" attribute (array) of the recording.

    For chat: If you are retrieving your recording via GET /api/v2/conversations/{conversationId}/recordings, which returns an array of recordings, you need to take the first one (recording) and get its "transcript" attribute -> I mean responseBody[0].transcript

    The messages in the transcript array are ordered - I mean index of messages goes from oldest message (index 0) to most recent (last message in transcript array). So you just need to loop through the array, and check bodyType ("STANDARD" or "NOTICE" for a message), participantPurpose for the role ("customer" for the customer, "agent" for the agent, "workflow" if you are sending messages from an Architect Chat Flow via "Send Response" action), and body for the content of the message.

    Assuming that you have stored the body of your "GET /api/v2/conversations/{conversationId}/recordings" response in a variable I will name responseBody (for this example code below). In javascript, the processing code would look like this:

    for (let message of responseBody[0].transcript) { if (message.bodyType === "STANDARD" || message.bodyType === "NOTICE") { if (message.participantPurpose === "customer") { console.log("Customer: ", message.body); } else if (message.participantPurpose === "workflow") { console.log("Contact Center Service: ", message.body); } else if (message.participantPurpose === "agent") { console.log("Agent: ", message.body); } } }


    Lee_Canady | 2020-05-08 07:33:44 UTC | #3

    Thanks for your quick response.

    I'm using Python SDK to run this API and the code is running in python local development server. In response, participant purpose value is 'NONE' everywhere. Please find the below request and response.


    Request:*

    for item in transcript:

    print(item)

    if (item.bodytype == "STANDARD" or item.bodytype == "NOTICE"):

    if (item.participant_purpose == "customer"):

    print("Customer: {} ", format(item.body))

    elif (item.participant_purpose == "workflow"):

    print("Contact Center Service: {} ", format(item.body))

    elif (item.participant_purpose == "agent"):

    print("Agent: {}", format(item.body))

    Response:

    {'body': 'Hello', 'bodytype': 'STANDARD', 'chat': '5eb504exxxxxxxxxxx', 'id': '5eb504xxxxxxxxxxxxx', 'message': None, 'participantpurpose': None, 'pcFrom': '5e854ecdxxxxxxx@xxxxxxxxxxxx.orgspan.com', 'sendercommunicationid': None, 'to': 'acd-b3f80369-2e08-42b1-a805-xxxxx@conference.1760.orgspan.com', 'type': 'message', 'user': None, 'utc': '2020-05-08T07:06:30.664Z'}

    {'body': 'How are you?', 'bodytype': 'STANDARD', 'chat': '5eb504edxxxxxxxxxxxx', 'id': '5eb504xxxxxxxxx', 'message': None, 'participantpurpose': None, 'pcFrom': '5e854ecxxxxxxxxxx@xxxxxxxxx.orgspan.com', 'sendercommunicationid': None, 'to': 'acd-b3f80369-2e08-42b1-a805-xxxxxx@conference.1760.orgspan.com', 'type': 'message', 'user': None, 'utc': '2020-05-08T07:06:33.291Z'}

    {'body': "I'm good.. I need help with one of my accounts", 'bodytype': 'STANDARD', 'chat': '5eb504edxxxxxxxxxxx', 'id': '5eb505xxxxxxxxxxxx', 'message': None, 'participantpurpose': None, 'pcFrom': '5eb504e2xxxxxxxxxxx@guest.orgspan.com', 'sendercommunicationid': None, 'to': 'acd-b3f80369-2e08-42b1-a805-xxxxxxx@conference.1760.orgspan.com', 'type': 'message', 'user': None, 'utc': '2020-05-08T07:06:55.392Z'}

    Please let me know if there is any configuration I'm missing out.


    Jerome.Saint-Marc | 2020-05-08 08:55:14 UTC | #4

    My apologies.

    I assumed (wrongly) that you were using a "PureCloud WebChat v2" - version2 of the chat protocol (the one triggered using Widgets v2). That is the type/version of chat the code I posted above was processing (transcript attributes are different in the 2 scenario).

    Seeing your python traces, I realize that you are using a "PureCloud Webchat" - version1 of the chat protocol (the one triggered using Widgets v1.0).

    With WebChat v1, I believe you will need one or two more API calls.

    [1] First would be to retrieve the conversation itself --> GET on /api/v2/conversations/{conversationId} In the returned conversation, you will have a structure/array for the participants ("participants" attribute name in the JSON response). You will have to look for the one corresponding to the customer (attribute "purpose" = "customer" - in an inbound chat scenario it should be the first participant in the participants array). In this participant structure, corresponding to the customer, there will be an "address" attribute which value will correspond to the one you see in pcFrom (when it is coming from the customer). In your logs, it should match what you have with 'pcFrom': '5eb504e2xxxxxxxxxxx@guest.orgspan.com'. These will be the messages from the customer.

    If the pcFrom in the transcript message doesn't match what you have found in the conversation --> $.participants[0].address, then it will be a message from the Agent (per Chat v1 scenario). If the chat is transferred between agents (if it is a possibility in your flow), and if you need to distinguish Agent1 from Agent2, you would need to run additional queries as described in [2] below.

    [2] If you wanted to be totally sure, you would need to make a request to a second API method. Still using the returned conversation you got from [1], you will have to look for the participant(s) corresponding to the agent(s) (attribute "purpose" = "agent"). When you have an agent participant (object/structure), you will take the "userId" attribute. You then need to get info on that user via a GET /api/v2/users/{userId}. The value used for the pcFrom of the agent will be in the response --> $.chat.jabberId In your logs, it should match what you have with 'pcFrom': '5e854ecdxxxxxxx@xxxxxxxxxxxx.orgspan.com'

    As an illustration:

    GET /api/v2/conversations/{myconversationid}

    { "id": "myconversationid", "startTime": "2020-05-08T08:19:37.143Z", "endTime": "2020-05-08T08:20:14.870Z", "participants": [ { "id": "....", ... "name": "Bill Myers", ... "purpose": "customer", "address": "xxxxxxxxxxxxxxx@guest.orgspan.com", .... }, { "id": "....", "purpose": "acd", ... }, { "id": "...", ... "userId": "myagentuser_id", ... "purpose": "agent", ... } ], ... }

    and

    GET /api/v2/users/{myagentuser_id}

    { "id": "myagentuser_id", ... "chat": { "jabberId": "yyyyyyyyyyy@devfoundry.orgspan.com" }, ... }

    Where transcript messages with "pcFrom" = "xxxxxxxxxxxxxxx@guest.orgspan.com" are the ones from my customer And transcript messages with "pcFrom" = "yyyyyyyyyyy@devfoundry.orgspan.com" are the ones from my agent (one agent involved in this scenario)

    If you are to move to Widgets v2 and PureCloud WebChat v2 one day, you will be able to leverage the code I initially posted.

    Hope this helps.

    Regards,


    anon39326996 | 2020-05-08 12:09:31 UTC | #5

    While there's no official deprecation of v1 chats at this time, please keep in mind is that we do eventually plan to deprecate v1 chats. Consider moving over to v2 now rather than investing effort into making v1 work really well for you.


    Lee_Canady | 2020-05-08 12:37:57 UTC | #6

    We need Co-Browse along with Chat and there was a note that Co-Browse is not available in version 2. Will Co-Browse work if we go with version 2?


    Lee_Canady | 2020-05-08 14:32:41 UTC | #7

    Thanks a lot.. It really helped!!


    charaf_ed | 2020-05-24 14:26:02 UTC | #8

    Jerome.Saint-Marc, post:2, topic:7736
    For chat: If you are retrieving your recording via GET /api/v2/conversations/{conversationId}/recordings, which returns an array of recordings, you need to take the first one (recording) and get its "transcript" attribute -> I mean responseBody[0].transcript

    Hello @Jerome.Saint-Marc,

    I have used the Get API mentioned above to retrieve chat trasncript and it works fine.

    But the problem is this API works only when the conversation is finished and the agent clicked the Done button to end the ACW.

    When you click the Done button, the script disappears and I cannot call APIs...

    Would it be a way to make a Get API automatically when the agent hits the Done button in order to retrieve chat recordings ?

    regards,

    CHARAF


    Jerome.Saint-Marc | 2020-05-25 09:55:14 UTC | #9

    Hello,

    No, at this time, there is no way to "automatically" trigger such API call.

    You would have to write a custom application (server-side, or client-side), that connects to the PureCloud org:

    • and that periodically checks chat conversations which have been ended during an interval (via Analytics API), that then retrieves the transcript via API and that stores it where you want (or sends it via a mail server to the customer).
    • or that subscribes to chat conversations topic (Notification API), that then retrieves the transcript via API when a chat conversation is finished (once ACW reason is set by the agent) and that stores it where you want (or sends it via a mail server to the customer).

    If you need to send the transcript to the customer via e-mail, note that at this time, only users/agents can trigger an outbound PureCloud e-mail (on behalf of a queue). If you create a server-side application (which would then leverage OAuth Client Credentials Grant), you would need to use a 3rd party email provider to submit the email.

    Regards,


    charaf_ed | 2020-05-25 11:20:18 UTC | #10

    Thank you @Jerome.Saint-Marc

    IT WORKS FINE using Notification API. I can retrieve the chat history when the agent hits the button Done automatically.

    For emails, I will try to send it using APIs since we have not integrated this channel yet in PureCloud.

    Regards,

    CHARAF


    system | 2020-06-25 11:20:21 UTC | #11

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


    This post was migrated from the old Developer Forum.

    ref: 7736