{
  "info": {
    "name": "HiveCFM – Genesys Bot Connector",
    "description": "Genesys Cloud **Bot Connector v1** API in HiveCFM: run a survey turn by turn inside a chat.\n\n## Setup (once)\n1. Collection → **Variables**: set `apiKey` (HiveCFM API key with **write** access to the environment). Check `baseUrl`, `envId`, `surveyId`.\n2. Auth is collection-level: header `x-api-key: {{apiKey}}`.\n\n## Try a chat\n1. **0. List bots**: expect 200.\n2. **1. Start survey**: new session, first question. Open **Visualize**.\n3. Set variable `answer` (e.g. `4`) → **2. Send answer**. Repeat until `botState` = **Complete**.\n   Or run **Examples** a → b → c after step 2.\n\n## Rules\n- Same `botSessionId` for every turn of one chat (scripts handle it).\n- `languageCode` `en-US` / `ar-SA` picks the survey language.\n- `botState`: MoreData = waiting for answer; Complete = finished or opted out; Failed = error.\n- Results: HiveCFM → survey → Responses (Source `genesys_bot_connector`).\n",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "apikey",
    "apikey": [
      {
        "key": "key",
        "value": "x-api-key",
        "type": "string"
      },
      {
        "key": "value",
        "value": "{{apiKey}}",
        "type": "string"
      },
      {
        "key": "in",
        "value": "header",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://dev.hivecfm.io"
    },
    {
      "key": "apiKey",
      "value": ""
    },
    {
      "key": "envId",
      "value": "cmt5pjft9000ikq01uokfllc8"
    },
    {
      "key": "surveyId",
      "value": "cmv78mcnv004en201dumw7c4h"
    },
    {
      "key": "languageCode",
      "value": "en-US"
    },
    {
      "key": "agentId",
      "value": "TEST-A12345"
    },
    {
      "key": "channel",
      "value": "webchat"
    },
    {
      "key": "answer",
      "value": "4"
    },
    {
      "key": "botSessionId",
      "value": ""
    },
    {
      "key": "conversationId",
      "value": ""
    },
    {
      "key": "lastBotState",
      "value": ""
    },
    {
      "key": "lastIntent",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "0. List bots",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
              "const b = pm.response.json().bots || [];",
              "pm.test(\"has bots\", () => pm.expect(b).to.not.be.empty);",
              "b.forEach(x => console.log(\"bot:\", x.id, \"|\", x.name, \"| versions:\", (x.versions || []).map(v => v.version).join(\",\")));"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/management/bot-connector/bots",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "management",
            "bot-connector",
            "bots"
          ]
        },
        "description": "Checks the API key and URL. Lists the bot HiveCFM exposes; in Genesys the bot is registered by hand (PUT /api/v2/integrations/botconnector/{integrationId}/bots). Expect `hivecfm-survey-bot`."
      }
    },
    {
      "name": "1. Start survey",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// New chat = new session. Later turns reuse these values automatically.",
              "pm.collectionVariables.set(\"botSessionId\", pm.variables.replaceIn(\"{{$guid}}\"));",
              "pm.collectionVariables.set(\"conversationId\", pm.variables.replaceIn(\"{{$guid}}\"));",
              "console.log(\"New botSessionId:\", pm.collectionVariables.get(\"botSessionId\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const j = pm.response.json();",
              "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
              "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
              "const texts = [], buttons = [];",
              "(j.replymessages || []).forEach(m => {",
              "  (m.content || []).forEach(c => {",
              "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
              "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
              "  });",
              "  if (!m.content && m.text) texts.push(m.text);",
              "});",
              "pm.collectionVariables.set(\"lastBotState\", j.botState);",
              "pm.collectionVariables.set(\"lastIntent\", j.intent);",
              "const next = j.botState === \"MoreData\"",
              "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
              "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
              "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
              "console.log(\"BOT:\", texts.join(\" | \"));",
              "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
              "console.log(\"NEXT:\", next);",
              "pm.visualizer.set(`",
              "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
              ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
              ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
              "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
              "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
              "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
              "<div class=\"next\">{{next}}</div>`,",
              "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "management",
            "bot-connector",
            "turn"
          ]
        },
        "description": "**First turn of a chat.** The pre-request script creates a new `botSessionId` and `conversationId`.\n\nRequired once per chat: `parameters.surveyId` and `parameters.environmentId`. Other `parameters` (agentId, channel, conversationId, contactId, …) are stored on the response as hidden fields.\n\nResponse: first question + buttons. Open the **Visualize** tab to read it like a chat.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"start\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\",\n  \"parameters\": {\n    \"surveyId\": \"{{surveyId}}\",\n    \"environmentId\": \"{{envId}}\",\n    \"agentId\": \"{{agentId}}\",\n    \"channel\": \"{{channel}}\",\n    \"conversationId\": \"{{conversationId}}\"\n  }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "2. Send answer",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (!pm.collectionVariables.get(\"botSessionId\")) {",
              "  console.warn(\"No session yet. Run '1. Start survey' first. Request skipped.\");",
              "  pm.execution.skipRequest();",
              "}"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const j = pm.response.json();",
              "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
              "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
              "const texts = [], buttons = [];",
              "(j.replymessages || []).forEach(m => {",
              "  (m.content || []).forEach(c => {",
              "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
              "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
              "  });",
              "  if (!m.content && m.text) texts.push(m.text);",
              "});",
              "pm.collectionVariables.set(\"lastBotState\", j.botState);",
              "pm.collectionVariables.set(\"lastIntent\", j.intent);",
              "const next = j.botState === \"MoreData\"",
              "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
              "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
              "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
              "console.log(\"BOT:\", texts.join(\" | \"));",
              "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
              "console.log(\"NEXT:\", next);",
              "pm.visualizer.set(`",
              "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
              ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
              ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
              "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
              "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
              "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
              "<div class=\"next\">{{next}}</div>`,",
              "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "management",
            "bot-connector",
            "turn"
          ]
        },
        "description": "**Every next turn.** Set the collection variable `answer`, then Send. Reuses the same `botSessionId`.\n\nButtons: send the `payload` (e.g. `4`) or the button text (e.g. `Yes`). Free-text questions: any text.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"{{answer}}\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "Examples",
      "description": "Ready-made answers for the demo survey. Run **1. Start survey** first, then these in order.",
      "item": [
        {
          "name": "a. Answer 4 (rating)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get(\"botSessionId\")) {",
                  "  console.warn(\"No session yet. Run '1. Start survey' first. Request skipped.\");",
                  "  pm.execution.skipRequest();",
                  "}",
                  "",
                  "pm.collectionVariables.set(\"answer\", \"4\");"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
                  "const texts = [], buttons = [];",
                  "(j.replymessages || []).forEach(m => {",
                  "  (m.content || []).forEach(c => {",
                  "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
                  "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
                  "  });",
                  "  if (!m.content && m.text) texts.push(m.text);",
                  "});",
                  "pm.collectionVariables.set(\"lastBotState\", j.botState);",
                  "pm.collectionVariables.set(\"lastIntent\", j.intent);",
                  "const next = j.botState === \"MoreData\"",
                  "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
                  "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
                  "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
                  "console.log(\"BOT:\", texts.join(\" | \"));",
                  "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
                  "console.log(\"NEXT:\", next);",
                  "pm.visualizer.set(`",
                  "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
                  ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
                  ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
                  "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
                  "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
                  "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
                  "<div class=\"next\">{{next}}</div>`,",
                  "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "management",
                "bot-connector",
                "turn"
              ]
            },
            "description": "Q1 answer = 4.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"{{answer}}\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "b. Answer Yes (choice)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get(\"botSessionId\")) {",
                  "  console.warn(\"No session yet. Run '1. Start survey' first. Request skipped.\");",
                  "  pm.execution.skipRequest();",
                  "}",
                  "",
                  "pm.collectionVariables.set(\"answer\", \"Yes\");"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
                  "const texts = [], buttons = [];",
                  "(j.replymessages || []).forEach(m => {",
                  "  (m.content || []).forEach(c => {",
                  "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
                  "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
                  "  });",
                  "  if (!m.content && m.text) texts.push(m.text);",
                  "});",
                  "pm.collectionVariables.set(\"lastBotState\", j.botState);",
                  "pm.collectionVariables.set(\"lastIntent\", j.intent);",
                  "const next = j.botState === \"MoreData\"",
                  "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
                  "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
                  "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
                  "console.log(\"BOT:\", texts.join(\" | \"));",
                  "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
                  "console.log(\"NEXT:\", next);",
                  "pm.visualizer.set(`",
                  "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
                  ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
                  ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
                  "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
                  "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
                  "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
                  "<div class=\"next\">{{next}}</div>`,",
                  "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "management",
                "bot-connector",
                "turn"
              ]
            },
            "description": "Q2 answer by button text.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"{{answer}}\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "c. Answer free text",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get(\"botSessionId\")) {",
                  "  console.warn(\"No session yet. Run '1. Start survey' first. Request skipped.\");",
                  "  pm.execution.skipRequest();",
                  "}",
                  "",
                  "pm.collectionVariables.set(\"answer\", \"Fast and friendly service\");"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
                  "const texts = [], buttons = [];",
                  "(j.replymessages || []).forEach(m => {",
                  "  (m.content || []).forEach(c => {",
                  "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
                  "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
                  "  });",
                  "  if (!m.content && m.text) texts.push(m.text);",
                  "});",
                  "pm.collectionVariables.set(\"lastBotState\", j.botState);",
                  "pm.collectionVariables.set(\"lastIntent\", j.intent);",
                  "const next = j.botState === \"MoreData\"",
                  "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
                  "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
                  "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
                  "console.log(\"BOT:\", texts.join(\" | \"));",
                  "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
                  "console.log(\"NEXT:\", next);",
                  "pm.visualizer.set(`",
                  "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
                  ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
                  ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
                  "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
                  "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
                  "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
                  "<div class=\"next\">{{next}}</div>`,",
                  "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "management",
                "bot-connector",
                "turn"
              ]
            },
            "description": "Q3. Last answer → botState Complete.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"{{answer}}\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Invalid answer 9",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get(\"botSessionId\")) {",
                  "  console.warn(\"No session yet. Run '1. Start survey' first. Request skipped.\");",
                  "  pm.execution.skipRequest();",
                  "}",
                  "",
                  "pm.collectionVariables.set(\"answer\", \"9\");"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
                  "const texts = [], buttons = [];",
                  "(j.replymessages || []).forEach(m => {",
                  "  (m.content || []).forEach(c => {",
                  "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
                  "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
                  "  });",
                  "  if (!m.content && m.text) texts.push(m.text);",
                  "});",
                  "pm.collectionVariables.set(\"lastBotState\", j.botState);",
                  "pm.collectionVariables.set(\"lastIntent\", j.intent);",
                  "const next = j.botState === \"MoreData\"",
                  "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
                  "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
                  "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
                  "console.log(\"BOT:\", texts.join(\" | \"));",
                  "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
                  "console.log(\"NEXT:\", next);",
                  "pm.visualizer.set(`",
                  "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
                  ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
                  ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
                  "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
                  "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
                  "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
                  "<div class=\"next\">{{next}}</div>`,",
                  "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "management",
                "bot-connector",
                "turn"
              ]
            },
            "description": "Not a valid button. With **Validate responses** on, HiveCFM sends the invalid-response message and asks again.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"{{answer}}\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Opt-out stop",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get(\"botSessionId\")) {",
                  "  console.warn(\"No session yet. Run '1. Start survey' first. Request skipped.\");",
                  "  pm.execution.skipRequest();",
                  "}",
                  "",
                  "pm.collectionVariables.set(\"answer\", \"stop\");"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
                  "const texts = [], buttons = [];",
                  "(j.replymessages || []).forEach(m => {",
                  "  (m.content || []).forEach(c => {",
                  "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
                  "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
                  "  });",
                  "  if (!m.content && m.text) texts.push(m.text);",
                  "});",
                  "pm.collectionVariables.set(\"lastBotState\", j.botState);",
                  "pm.collectionVariables.set(\"lastIntent\", j.intent);",
                  "const next = j.botState === \"MoreData\"",
                  "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
                  "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
                  "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
                  "console.log(\"BOT:\", texts.join(\" | \"));",
                  "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
                  "console.log(\"NEXT:\", next);",
                  "pm.visualizer.set(`",
                  "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
                  ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
                  ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
                  "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
                  "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
                  "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
                  "<div class=\"next\">{{next}}</div>`,",
                  "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "management",
                "bot-connector",
                "turn"
              ]
            },
            "description": "Ends the chat. Opt-out words: stop, quit, cancel, unsubscribe, opt out, optout, no thanks → intent `survey_opted_out`.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"{{answer}}\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Start survey in Arabic",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// New chat = new session. Later turns reuse these values automatically.",
                  "pm.collectionVariables.set(\"botSessionId\", pm.variables.replaceIn(\"{{$guid}}\"));",
                  "pm.collectionVariables.set(\"conversationId\", pm.variables.replaceIn(\"{{$guid}}\"));",
                  "console.log(\"New botSessionId:\", pm.collectionVariables.get(\"botSessionId\"));",
                  "pm.collectionVariables.set(\"languageCode\", \"ar-SA\");"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "pm.test(\"HTTP 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"valid botState\", () => pm.expect(j.botState).to.be.oneOf([\"MoreData\", \"Complete\", \"Failed\"]));",
                  "const texts = [], buttons = [];",
                  "(j.replymessages || []).forEach(m => {",
                  "  (m.content || []).forEach(c => {",
                  "    if (c.contentType === \"Text\" && c.text) texts.push(c.text);",
                  "    if (c.contentType === \"QuickReply\" && c.quickReply) buttons.push(c.quickReply);",
                  "  });",
                  "  if (!m.content && m.text) texts.push(m.text);",
                  "});",
                  "pm.collectionVariables.set(\"lastBotState\", j.botState);",
                  "pm.collectionVariables.set(\"lastIntent\", j.intent);",
                  "const next = j.botState === \"MoreData\"",
                  "  ? (buttons.length ? \"Set variable 'answer' to one payload below, then send '2. Send answer'.\"",
                  "                    : \"Free text: set variable 'answer' to any text, then send '2. Send answer'.\")",
                  "  : \"Chat finished (\" + j.intent + \"). Run '1. Start survey' for a new chat.\";",
                  "console.log(\"BOT:\", texts.join(\" | \"));",
                  "buttons.forEach(b => console.log(\"  button:\", b.text, \"-> payload:\", b.payload));",
                  "console.log(\"NEXT:\", next);",
                  "pm.visualizer.set(`",
                  "<style>body{font-family:Segoe UI,Arial;padding:10px}.bot{background:#eef2f7;border-radius:10px;padding:10px 14px;margin:6px 0;max-width:560px}",
                  ".btn{display:inline-block;border:1px solid #1f3a5f;border-radius:16px;padding:4px 12px;margin:4px;font-size:13px}.pl{color:#888;font-size:11px}",
                  ".meta{color:#555;font-size:12px;margin-top:10px}.next{background:#fff7e6;border-left:4px solid #d97706;padding:8px;margin-top:10px}</style>",
                  "{{#each texts}}<div class=\"bot\" dir=\"auto\">{{this}}</div>{{/each}}",
                  "<div>{{#each buttons}}<span class=\"btn\" dir=\"auto\">{{text}} <span class=\"pl\">payload={{payload}}</span></span>{{/each}}</div>",
                  "<div class=\"meta\">botState: <b>{{state}}</b> &nbsp; intent: <b>{{intent}}</b> &nbsp; session: {{session}}</div>",
                  "<div class=\"next\">{{next}}</div>`,",
                  "  { texts, buttons, state: j.botState, intent: j.intent, session: pm.collectionVariables.get(\"botSessionId\"), next });"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/api/v1/management/bot-connector/turn",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "api",
                "v1",
                "management",
                "bot-connector",
                "turn"
              ]
            },
            "description": "Sets `languageCode` = `ar-SA` and starts a new chat → Arabic text and buttons. Continue with **2. Send answer** (stays Arabic). Set `languageCode` back to `en-US` for English.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"botSessionId\": \"{{botSessionId}}\",\n  \"inputMessage\": {\n    \"type\": \"Text\",\n    \"text\": \"start\"\n  },\n  \"languageCode\": \"{{languageCode}}\",\n  \"genesysConversationId\": \"{{conversationId}}\",\n  \"parameters\": {\n    \"surveyId\": \"{{surveyId}}\",\n    \"environmentId\": \"{{envId}}\",\n    \"agentId\": \"{{agentId}}\",\n    \"channel\": \"{{channel}}\",\n    \"conversationId\": \"{{conversationId}}\"\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    }
  ]
}