{
  "name": "Huga — atendimento finalizado vira linha no Google Sheets",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": null,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Huga (webhook) — ligue JSON pass-through e Get request headers"
        }
      }
    },
    {
      "id": 2,
      "module": "json:ParseJSON",
      "version": 1,
      "parameters": {
        "type": null
      },
      "filter": {
        "name": "Assinatura do Huga confere e é atendimento.finalizado",
        "conditions": [
          [
            {
              "a": "{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"x-hugi-signature-256\"); 1)}}",
              "b": "sha256={{sha256(1.value; \"hex\"; \"COLE_AQUI_O_SEGREDO_DO_ENDPOINT\")}}",
              "o": "text:equal"
            }
          ]
        ]
      },
      "mapper": {
        "json": "{{1.value}}"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Ler o corpo"
        }
      }
    },
    {
      "id": 3,
      "module": "google-sheets:addRow",
      "version": 2,
      "parameters": {
        "__IMTCONN__": null
      },
      "filter": {
        "name": "Só encerramento",
        "conditions": [
          [
            {
              "a": "{{2.atendimento.estado}}",
              "b": "finalizado",
              "o": "text:equal"
            }
          ]
        ]
      },
      "mapper": {
        "mode": "select",
        "spreadsheetId": "",
        "sheetId": "Atendimentos",
        "includesHeaders": true,
        "insertUnformatted": false,
        "valueInputOption": "USER_ENTERED",
        "insertDataOption": "INSERT_ROWS",
        "values": {
          "0": "{{ifempty(get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"x-hugi-entrega\"); 1); 2.atendimento.id + \":\" + 2.atendimento.finalizadoEm)}}",
          "1": "{{2.atendimento.finalizadoEm}}",
          "2": "{{2.atendimento.protocolo}}",
          "3": "{{ifempty(2.contato.nome; 2.contato.nomeDoPerfil)}}",
          "4": "{{2.contato.identificador}}",
          "5": "{{2.atendimento.canal}}",
          "6": "{{2.atendimento.fila.nome}}",
          "7": "{{2.atendimento.motivo}}",
          "8": "{{2.atendimento.observacao}}",
          "9": "{{if(2.atendimento.automatico; \"sim\"; \"não\")}}",
          "10": "{{2.atendimento.abertoEm}}",
          "11": "{{round(2.esperaSegundos / 6) / 10}}",
          "12": "{{round(2.atendimentoSegundos / 6) / 10}}",
          "13": "{{2.atendimento.id}}"
        }
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Google Sheets: uma linha por atendimento"
        }
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    }
  }
}
