[
  {
    "id": "855a8dd4776456c9",
    "type": "aiwk-in",
    "z": "73394bf33c3e3369",
    "name": "N1 aiwk_ping 수신",
    "server": "18af01daa1a16f24",
    "inputEndpoint": "node-red",
    "filterAction": "aiwk_ping",
    "allowAnyEndpoint": false,
    "x": 190,
    "y": 820,
    "wires": [
      [
        "4fdc1c42a0444270"
      ]
    ]
  },
  {
    "id": "4fdc1c42a0444270",
    "type": "function",
    "z": "73394bf33c3e3369",
    "name": "aiwk_ping →  HOST1 aiwk_pong",
    "func": "const p = msg.aiwk || msg.payload || {};\nconst sent = Number(p.client_ts || p.sent_at_ms || (p.args && p.args.client_ts) || (p.payload && p.payload.client_ts) || Date.now());\nmsg.aiwk_type = \"result\";\nmsg.aiwk_action = \"aiwk_pong\";\nmsg.aiwk_to = p.from || \"HOST1\";\nmsg.aiwk_from = \"N1\";\nmsg.aiwk_msg_id = \"pong_\" + Date.now();\nmsg.aiwk_reply_to = p.message_id || p.msg_id || \"\";\nmsg.aiwk_reply_to_message_id = p.message_id || p.msg_id || \"\";\nmsg.chat_id = p.chat_id || \"home.IG_CRM\";\nmsg.message_id = msg.aiwk_msg_id;\nmsg.reply_to_message_id = msg.aiwk_reply_to_message_id;\nmsg.client_ts = sent;\nmsg.sent_at_ms = Date.now();\nmsg.payload = {\n    kind: \"pong\",\n    from: \"N1\",\n    to: msg.aiwk_to,\n    reply_to_message_id: msg.reply_to_message_id,\n    client_ts: sent,\n    node_red_ms: Date.now()\n};\nmsg.result = msg.payload;\nnode.status({ fill: \"green\", shape: \"dot\", text: \"PONG → \" + msg.aiwk_to });\nreturn msg;",
    "outputs": 1,
    "timeout": 0,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 360,
    "y": 900,
    "wires": [
      [
        "55e4ab1fcc055985"
      ]
    ]
  },
  {
    "id": "55e4ab1fcc055985",
    "type": "aiwk-out",
    "z": "73394bf33c3e3369",
    "name": "aiwk_pong 회신",
    "server": "18af01daa1a16f24",
    "fromEndpoint": "node-red",
    "to": "",
    "action": "aiwk_pong",
    "needAck": false,
    "needResult": false,
    "timeoutMs": 10000,
    "x": 520,
    "y": 820,
    "wires": [
      [
        "1637ac906fd3c0e8"
      ]
    ]
  },
  {
    "id": "1637ac906fd3c0e8",
    "type": "function",
    "z": "73394bf33c3e3369",
    "name": "PONG 송신 상태",
    "func": "node.status({ fill: msg.aiwk_sent ? \"green\" : \"red\", shape: \"ring\", text: JSON.stringify({sent:msg.aiwk_sent,to:msg.aiwk_to,reply_to:msg.reply_to_message_id}) });\nreturn msg;",
    "outputs": 1,
    "timeout": 0,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 680,
    "y": 880,
    "wires": [
      []
    ]
  },
  {
    "id": "18af01daa1a16f24",
    "type": "aiwk-config",
    "name": "aiwk",
    "wssUrl": "wss://n.yjm.kr/aiwk/ws",
    "profileApiUrl": "https://n.yjm.kr/y/aiwk_profile_api.php",
    "group": "home",
    "project": "IG_CRM",
    "room": "RE5ay2jRmY",
    "clientId": "N1",
    "endpointBase": "node-red",
    "autoConnect": true,
    "reconnectMs": 3000
  },
  {
    "id": "v059_chat_in",
    "type": "aiwk-in",
    "z": "73394bf33c3e3369",
    "name": "N1 aiwk_chat 수신",
    "server": "18af01daa1a16f24",
    "inputEndpoint": "node-red",
    "filterAction": "aiwk_chat",
    "allowAnyEndpoint": false,
    "x": 190,
    "y": 980,
    "wires": [
      [
        "v059_chat_fn"
      ]
    ]
  },
  {
    "id": "v059_chat_fn",
    "type": "function",
    "z": "73394bf33c3e3369",
    "name": "aiwk_chat → 보낸 사람에게 ACK",
    "func": "const p = msg.aiwk || msg.payload || {};\nconst text = (p.payload && p.payload.text) || msg.payload.text || msg.payload.raw_text || '';\nmsg.aiwk_type = 'result';\nmsg.aiwk_action = 'aiwk_chat_ack';\nmsg.aiwk_to = p.from || 'HOST1';\nmsg.aiwk_from = 'N1';\nmsg.aiwk_msg_id = 'chatack_' + Date.now();\nmsg.aiwk_reply_to = p.message_id || p.msg_id || '';\nmsg.aiwk_reply_to_message_id = msg.aiwk_reply_to;\nmsg.chat_id = p.chat_id || 'home.IG_CRM';\nmsg.message_id = msg.aiwk_msg_id;\nmsg.reply_to_message_id = msg.aiwk_reply_to;\nmsg.payload = { ok:1, kind:'chat_ack', from:'N1', to:msg.aiwk_to, text:text, node_red_ms:Date.now() };\nmsg.result = msg.payload;\nnode.status({ fill:'green', shape:'dot', text:'CHAT ACK → ' + msg.aiwk_to });\nreturn msg;",
    "outputs": 1,
    "timeout": 0,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 390,
    "y": 980,
    "wires": [
      [
        "v059_chat_out"
      ]
    ]
  },
  {
    "id": "v059_chat_out",
    "type": "aiwk-out",
    "z": "73394bf33c3e3369",
    "name": "aiwk_chat_ack 회신",
    "server": "18af01daa1a16f24",
    "fromEndpoint": "node-red",
    "to": "",
    "action": "aiwk_chat_ack",
    "needAck": false,
    "needResult": false,
    "timeoutMs": 10000,
    "x": 590,
    "y": 980,
    "wires": [
      []
    ]
  }
]