# Analyze Conversation using AI

<figure><img src="/files/rZnkiXP8qqQqpvsY5kFc" alt=""><figcaption><p>Use GET Method for API Conversation and Analyze using AI</p></figcaption></figure>

## Objective

## Node

{% stepper %}
{% step %}

### Trigger

{% hint style="info" %}
You can replace this with another trigger
{% endhint %}
{% endstep %}

{% step %}

### Postgre

{% hint style="info" %}
You can replace with your data source
{% endhint %}

<figure><img src="/files/nwazeHIdYCa9Xzr7yYcV" alt=""><figcaption><p>Node : Postgre</p></figcaption></figure>

{% code title="example: postgre output" overflow="wrap" lineNumbers="true" %}

```json
[
  {
    "uid": "ae20ec30-3106-4f3b-9947-fd70cd4c5ea8",
    "timestamp": "2024-11-12T00:00:00.000Z",
    "phone": "62800000000",
    "email": null,
    "name": "Eva",
    "gender": null,
    "date_of_birth": null,
    "age": null,
    "age_group": "",
    "branch": "KYZN",
    "language": null,
    "contact_owner": "Wahyu Hermawan",
    "source": "meta_ads",
    "sremarks": "120211373562470678",
    "content": null,
    "medium": "sleekflow",
    "mremarks": "wa",
    "assigned_pic": null,
    "interest": null,
    "leads_notes": null,
    "leads_qualification": "Inbound",
    "user_type": null,
    "kyzn_account": null,
    "sleekflow_id": "ae20ec30-3106-4f3b-9947-fd70cd4c5ea8",
    "leads_date": null,
    "mql_date": null,
    "mqlPlus_date": null,
    "tourPlus_date": null,
    "convert_date": null,
    "loss_date": null,
    "tour_date": null,
    "is_tour_show?": null,
    "trial_date": null,
    "is_trial_show?": null,
    "is_inbound?": true,
    "is_leads?": null,
    "is_mql?": null,
    "is_mqlPlus?": null,
    "is_tourPlus?": null,
    "is_trialPlus?": null,
    "is_convert?": null,
    "interest_remarks": null,
    "submitted_email": null,
    "assigned_email": null,
    "trialPlus_date": null,
    "membership_name": null,
    "package_name": null,
    "start_membership": null,
    "member_id": null,
    "total_amount": null,
    "payment_method": null,
    "promotion": null,
    "ref_program": null,
    "ref_id": null,
    "ref_name": null,
    "ref_phone": null,
    "identity_photo": null,
    "status": null,
    "convert_by": null,
    "end_membership": null,
    "signature": null,
    "contract": null,
    "offer_trial": null,
    "reply_after_offer": null,
    "last_appt_category": null,
    "conversationId": "504b8ae5-d230-4f68-9600-4240c83f9365",
    "assigned_date": "2024-11-12T03:14:32.000Z",
    "last_created_by": null,
    "is_renewal": null,
    "approach_by": "Annisa",
    "app_status": null,
    "start_approach": null,
    "expired_approach": null,
    "hide": null,
    "id": "50dfdf8e-81e5-11122024-0180-10278ee961d2",
    "convert_category": null,
    "renewal_category": null,
    "is_package": null,
    "q1_rate_class": null,
    "last_update": null,
    "pic_update": null
  }
]
```

{% endcode %}

{% endstep %}

{% step %}

### HTTP Request (Sleekflow Get Conversation)

<figure><img src="/files/jUCmA8XZEPxBmuVK6PNH" alt=""><figcaption><p>Node : HTTP Request</p></figcaption></figure>

{% hint style="info" %}
In this tutorial, I use SleekFlow as the my omnichannel platform. You can use your own omnichannel platform.\
\
Read this : <https://apidoc.sleekflow.io/docs/platform-api/14a846659061d-get-messages-in-conversation>
{% endhint %}

<table><thead><tr><th width="259">Parameters/Auth</th><th>Value</th></tr></thead><tbody><tr><td><strong>Method</strong></td><td>GET</td></tr><tr><td><strong>URL</strong></td><td>https://api.sleekflow.io/api/conversation/message/<code>{{ $json.conversationId }}</code>?limit=10</td></tr><tr><td><strong>X-Sleekflow-Api-Key</strong></td><td><code>[YOUR API KEY]</code></td></tr></tbody></table>

{% code overflow="wrap" %}

```sh
curl --request GET
--url https://api.sleekflow.io/api/conversation/message/{conversationId}
--header 'Accept: application/json'
--header 'X-Sleekflow-Api-Key: 123'
```

{% endcode %}

{% endstep %}

{% step %}

### Code (Combining Conversation)&#x20;

{% endstep %}

{% step %}

### AI Agent (Conversational Agent)

{% endstep %}

{% step %}

### Code (Result)

<figure><img src="/files/cQf9sUqM2ZvTesQtQ3kc" alt=""><figcaption><p>Result AI</p></figcaption></figure>

{% code title="code: result" overflow="wrap" lineNumbers="true" %}

```javascript
// Code Node: Parse AI Agent's JSON Output and Extract Values
return items.map(item => {
  const jsonString = item.json.output; // Use 'output' as the field name

  let parsedData;
  try {
    // Parse the JSON string from the AI agent's output
    parsedData = JSON.parse(jsonString);
  } catch (error) {
    throw new Error('Failed to parse JSON: ' + error.message);
  }

  // Return the extracted values in the desired format
  return {
    json: {
      interest: parsedData.interest || '',
      interest_remarks: parsedData.interest_remarks || '',
      offer_trial: parsedData.offer_trial || false,
      reply_after_offer: parsedData.reply_after_offer || false
    }
  };
});
```

{% endcode %}

{% code title="return: result" overflow="wrap" lineNumbers="true" %}

```json
[
  {
    "interest": "Junior Anytime Class",
    "interest_remarks": "Paket untuk anak 5 tahun.",
    "offer_trial": true,
    "reply_after_offer": false
  },
  {
    "interest": "Adult Regular Class",
    "interest_remarks": "Sunset Yoga 3.0 event invitation.",
    "offer_trial": true,
    "reply_after_offer": false
  },
  {
    "interest": "Other Inquiry",
    "interest_remarks": "No valid messages to analyze.",
    "offer_trial": false,
    "reply_after_offer": false
  }
]
```

{% endcode %}

{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://work.bahrul.me/work/kyzn/automation/analyze-conversation-using-ai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
