[{"data":1,"prerenderedAt":3265},["ShallowReactive",2],{"navigation_docs_pt":3,"-pt-api-guides-sync-calls-crm":706,"-pt-api-guides-sync-calls-crm-surround":3260},[4,8,26,52,101,131,181,219,237,247,269,291,562,572,613,662,692],{"title":5,"path":6,"stem":7},"Introdução","\u002Fpt\u002Fintroduction","pt\u002F01.introduction",{"title":9,"path":10,"stem":11,"children":12},"Começar","\u002Fpt\u002Fgetting-started","pt\u002F02.getting-started\u002Findex",[13,14,18,22],{"title":9,"path":10,"stem":11},{"title":15,"path":16,"stem":17},"Configuração inicial","\u002Fpt\u002Fgetting-started\u002Finitial-setup","pt\u002F02.getting-started\u002F01.initial-setup",{"title":19,"path":20,"stem":21},"Criar o primeiro agente","\u002Fpt\u002Fgetting-started\u002Ffirst-agent","pt\u002F02.getting-started\u002F02.first-agent",{"title":23,"path":24,"stem":25},"Fazer uma chamada de teste","\u002Fpt\u002Fgetting-started\u002Ftest-call","pt\u002F02.getting-started\u002F03.test-call",{"title":27,"path":28,"stem":29,"children":30},"Conceitos","\u002Fpt\u002Fconcepts","pt\u002F03.concepts\u002Findex",[31,32,36,40,44,48],{"title":27,"path":28,"stem":29},{"title":33,"path":34,"stem":35},"Agente de voz","\u002Fpt\u002Fconcepts\u002Fagent","pt\u002F03.concepts\u002F01.agent",{"title":37,"path":38,"stem":39},"Fluxo","\u002Fpt\u002Fconcepts\u002Fflow","pt\u002F03.concepts\u002F02.flow",{"title":41,"path":42,"stem":43},"Runtime","\u002Fpt\u002Fconcepts\u002Fruntime","pt\u002F03.concepts\u002F03.runtime",{"title":45,"path":46,"stem":47},"Organização e permissões","\u002Fpt\u002Fconcepts\u002Forganization","pt\u002F03.concepts\u002F04.organization",{"title":49,"path":50,"stem":51},"Prompt Builder","\u002Fpt\u002Fconcepts\u002Fprompt-builder","pt\u002F03.concepts\u002F05.prompt-builder",{"title":53,"path":54,"stem":55,"children":56},"Guias","\u002Fpt\u002Fguides","pt\u002F04.guides\u002Findex",[57,58,61,65,69,73,77,81,85,89,93,97],{"title":53,"path":54,"stem":55},{"title":19,"path":59,"stem":60},"\u002Fpt\u002Fguides\u002Fcreate-first-agent","pt\u002F04.guides\u002F01.create-first-agent",{"title":62,"path":63,"stem":64},"Usar o Flow Builder","\u002Fpt\u002Fguides\u002Fuse-flow-builder","pt\u002F04.guides\u002F02.use-flow-builder",{"title":66,"path":67,"stem":68},"Publicar e receber chamadas","\u002Fpt\u002Fguides\u002Fpublish-agent","pt\u002F04.guides\u002F03.publish-agent",{"title":70,"path":71,"stem":72},"Testar um agente","\u002Fpt\u002Fguides\u002Ftest-agent","pt\u002F04.guides\u002F04.test-agent",{"title":74,"path":75,"stem":76},"Transferir para humano","\u002Fpt\u002Fguides\u002Ftransfer-to-human","pt\u002F04.guides\u002F05.transfer-to-human",{"title":78,"path":79,"stem":80},"Marcar reuniões com Cal.com","\u002Fpt\u002Fguides\u002Fbook-meetings","pt\u002F04.guides\u002F06.book-meetings",{"title":82,"path":83,"stem":84},"Enviar SMS","\u002Fpt\u002Fguides\u002Fsend-sms","pt\u002F04.guides\u002F07.send-sms",{"title":86,"path":87,"stem":88},"Configurar uma lista telefónica","\u002Fpt\u002Fguides\u002Fconfigure-phone-book","pt\u002F04.guides\u002F08.configure-phone-book",{"title":90,"path":91,"stem":92},"Incorporar o widget de voz","\u002Fpt\u002Fguides\u002Fembed-widget","pt\u002F04.guides\u002F09.embed-widget",{"title":94,"path":95,"stem":96},"Gravar chamadas","\u002Fpt\u002Fguides\u002Frecord-calls","pt\u002F04.guides\u002F10.record-calls",{"title":98,"path":99,"stem":100},"Ocultar dados pessoais","\u002Fpt\u002Fguides\u002Fredact-personal-data","pt\u002F04.guides\u002F11.redact-personal-data",{"title":102,"path":103,"stem":104,"children":105},"Flow Builder","\u002Fpt\u002Fflow-builder","pt\u002F05.flow-builder\u002Findex",[106,107,111,115,119,123,127],{"title":102,"path":103,"stem":104},{"title":108,"path":109,"stem":110},"Interface do builder","\u002Fpt\u002Fflow-builder\u002Finterface","pt\u002F05.flow-builder\u002F01.interface",{"title":112,"path":113,"stem":114},"Estrutura de um fluxo","\u002Fpt\u002Fflow-builder\u002Fstructure","pt\u002F05.flow-builder\u002F02.structure",{"title":116,"path":117,"stem":118},"Variáveis do fluxo","\u002Fpt\u002Fflow-builder\u002Fvariables","pt\u002F05.flow-builder\u002F03.variables",{"title":120,"path":121,"stem":122},"Condições e caminhos","\u002Fpt\u002Fflow-builder\u002Fbranches","pt\u002F05.flow-builder\u002F04.branches",{"title":124,"path":125,"stem":126},"Testar um fluxo","\u002Fpt\u002Fflow-builder\u002Ftesting","pt\u002F05.flow-builder\u002F05.testing",{"title":128,"path":129,"stem":130},"Validação e publicação","\u002Fpt\u002Fflow-builder\u002Fvalidation-publishing","pt\u002F05.flow-builder\u002F06.validation-publishing",{"title":132,"path":133,"stem":134,"children":135},"Nós","\u002Fpt\u002Fnodes","pt\u002F06.nodes\u002Findex",[136,137,141,145,149,153,157,161,165,169,173,177],{"title":132,"path":133,"stem":134},{"title":138,"path":139,"stem":140},"Conversação","\u002Fpt\u002Fnodes\u002Fconversation","pt\u002F06.nodes\u002F01.conversation",{"title":142,"path":143,"stem":144},"Mensagem","\u002Fpt\u002Fnodes\u002Fmessage","pt\u002F06.nodes\u002F02.message",{"title":146,"path":147,"stem":148},"Dividir o caminho","\u002Fpt\u002Fnodes\u002Fsplit-path","pt\u002F06.nodes\u002F03.split-path",{"title":150,"path":151,"stem":152},"Saltar para","\u002Fpt\u002Fnodes\u002Fjump-to","pt\u002F06.nodes\u002F04.jump-to",{"title":154,"path":155,"stem":156},"Disparar subfluxo","\u002Fpt\u002Fnodes\u002Ftrigger-subflow","pt\u002F06.nodes\u002F05.trigger-subflow",{"title":158,"path":159,"stem":160},"Acção personalizada","\u002Fpt\u002Fnodes\u002Fcustom-action","pt\u002F06.nodes\u002F06.custom-action",{"title":162,"path":163,"stem":164},"Enviar SMS durante a chamada","\u002Fpt\u002Fnodes\u002Fsend-sms-during-call","pt\u002F06.nodes\u002F07.send-sms-during-call",{"title":166,"path":167,"stem":168},"Transferência","\u002Fpt\u002Fnodes\u002Ftransfer","pt\u002F06.nodes\u002F08.transfer",{"title":170,"path":171,"stem":172},"Agendamento","\u002Fpt\u002Fnodes\u002Fbooking","pt\u002F06.nodes\u002F09.booking",{"title":174,"path":175,"stem":176},"Terminar chamada","\u002Fpt\u002Fnodes\u002Fend-call","pt\u002F06.nodes\u002F10.end-call",{"title":178,"path":179,"stem":180},"Nós em breve","\u002Fpt\u002Fnodes\u002Fcoming-soon","pt\u002F06.nodes\u002F11.coming-soon",{"title":182,"path":183,"stem":184,"children":185},"Acções","\u002Fpt\u002Factions","pt\u002F07.actions\u002Findex",[186,187,191,195,199,203,207,211,215],{"title":182,"path":183,"stem":184},{"title":188,"path":189,"stem":190},"Transferências de chamada","\u002Fpt\u002Factions\u002Fcall-transfers","pt\u002F07.actions\u002F01.call-transfers",{"title":192,"path":193,"stem":194},"IVR","\u002Fpt\u002Factions\u002Fivr","pt\u002F07.actions\u002F02.ivr",{"title":196,"path":197,"stem":198},"SMS durante a chamada","\u002Fpt\u002Factions\u002Fduring-call-sms","pt\u002F07.actions\u002F03.during-call-sms",{"title":200,"path":201,"stem":202},"SMS pós-chamada","\u002Fpt\u002Factions\u002Fpost-call-sms","pt\u002F07.actions\u002F04.post-call-sms",{"title":204,"path":205,"stem":206},"Acções personalizadas","\u002Fpt\u002Factions\u002Fcustom-actions","pt\u002F07.actions\u002F05.custom-actions",{"title":208,"path":209,"stem":210},"Extratores de Informação","\u002Fpt\u002Factions\u002Finformation-extractors","pt\u002F07.actions\u002F06.information-extractors",{"title":212,"path":213,"stem":214},"Avaliações Personalizadas","\u002Fpt\u002Factions\u002Fcustom-evaluations","pt\u002F07.actions\u002F07.custom-evaluations",{"title":216,"path":217,"stem":218},"Agendamento em tempo real","\u002Fpt\u002Factions\u002Freal-time-booking","pt\u002F07.actions\u002F08.real-time-booking",{"title":220,"path":221,"stem":222,"children":223},"Base de conhecimento","\u002Fpt\u002Fknowledge-base","pt\u002F08.knowledge-base\u002Findex",[224,225,229,233],{"title":220,"path":221,"stem":222},{"title":226,"path":227,"stem":228},"Fontes","\u002Fpt\u002Fknowledge-base\u002Fsources","pt\u002F08.knowledge-base\u002F01.sources",{"title":230,"path":231,"stem":232},"Citações","\u002Fpt\u002Fknowledge-base\u002Fcitations","pt\u002F08.knowledge-base\u002F02.citations",{"title":234,"path":235,"stem":236},"Memória partilhada","\u002Fpt\u002Fknowledge-base\u002Fshared-memory","pt\u002F08.knowledge-base\u002F03.shared-memory",{"title":238,"path":239,"stem":240,"children":241},"Centro de Testes","\u002Fpt\u002Ftest-center","pt\u002F09.test-center\u002Findex",[242,243],{"title":238,"path":239,"stem":240},{"title":244,"path":245,"stem":246},"Avaliações","\u002Fpt\u002Ftest-center\u002Fevaluations","pt\u002F09.test-center\u002F01.evaluations",{"title":248,"path":249,"stem":250,"children":251},"Históricos e análises","\u002Fpt\u002Fhistory","pt\u002F10.history\u002Findex",[252,253,257,261,265],{"title":248,"path":249,"stem":250},{"title":254,"path":255,"stem":256},"Visão geral","\u002Fpt\u002Fhistory\u002Fdashboard","pt\u002F10.history\u002F01.dashboard",{"title":258,"path":259,"stem":260},"Chamadas","\u002Fpt\u002Fhistory\u002Fcalls","pt\u002F10.history\u002F02.calls",{"title":262,"path":263,"stem":264},"Gravações","\u002Fpt\u002Fhistory\u002Frecordings","pt\u002F10.history\u002F03.recordings",{"title":266,"path":267,"stem":268},"Análises","\u002Fpt\u002Fhistory\u002Fanalytics","pt\u002F10.history\u002F04.analytics",{"title":270,"path":271,"stem":272,"children":273},"WhatsApp","\u002Fpt\u002Fwhatsapp","pt\u002F11.whatsapp\u002Findex",[274,275,279,283,287],{"title":270,"path":271,"stem":272},{"title":276,"path":277,"stem":278},"Ligar o número","\u002Fpt\u002Fwhatsapp\u002Fconnect","pt\u002F11.whatsapp\u002F01.connect",{"title":280,"path":281,"stem":282},"Templates","\u002Fpt\u002Fwhatsapp\u002Ftemplates","pt\u002F11.whatsapp\u002F02.templates",{"title":284,"path":285,"stem":286},"Conversas","\u002Fpt\u002Fwhatsapp\u002Fconversations","pt\u002F11.whatsapp\u002F03.conversations",{"title":288,"path":289,"stem":290},"Chamadas de voz","\u002Fpt\u002Fwhatsapp\u002Fcalls","pt\u002F11.whatsapp\u002F04.calls",{"title":292,"path":293,"stem":294,"children":295},"API","\u002Fpt\u002Fapi","pt\u002F12.api\u002Findex",[296,297,301,305,309,313,317,321,536,554,558],{"title":292,"path":293,"stem":294},{"title":298,"path":299,"stem":300},"Começar com a API","\u002Fpt\u002Fapi\u002Fgetting-started","pt\u002F12.api\u002F01.getting-started",{"title":302,"path":303,"stem":304},"API da DISKA","\u002Fpt\u002Fapi\u002Fapi-channel","pt\u002F12.api\u002F02.api-channel",{"title":306,"path":307,"stem":308},"Autenticação","\u002Fpt\u002Fapi\u002Fauthentication","pt\u002F12.api\u002F03.authentication",{"title":310,"path":311,"stem":312},"Webhooks","\u002Fpt\u002Fapi\u002Fwebhooks","pt\u002F12.api\u002F04.webhooks",{"title":314,"path":315,"stem":316},"Endpoints","\u002Fpt\u002Fapi\u002Fendpoints","pt\u002F12.api\u002F05.endpoints",{"title":318,"path":319,"stem":320},"Tempo real","\u002Fpt\u002Fapi\u002Frealtime","pt\u002F12.api\u002F06.realtime",{"title":322,"path":323,"stem":324,"children":325},"Referência da API","\u002Fpt\u002Fapi\u002Freference","pt\u002F12.api\u002F07.reference\u002Findex",[326,327,337,363,380,398,440,466,475,485,511],{"title":322,"path":323,"stem":324},{"title":328,"path":329,"stem":330,"children":331},"Identidade","\u002Fpt\u002Fapi\u002Freference\u002Fidentity","pt\u002F12.api\u002F07.reference\u002F01.identity\u002Findex",[332,333],{"title":328,"path":329,"stem":330},{"title":334,"path":335,"stem":336},"Ver a chave e a organização","\u002Fpt\u002Fapi\u002Freference\u002Fidentity\u002Fget-identity","pt\u002F12.api\u002F07.reference\u002F01.identity\u002F01.get-identity",{"title":338,"path":339,"stem":340,"children":341},"Agentes","\u002Fpt\u002Fapi\u002Freference\u002Fagents","pt\u002F12.api\u002F07.reference\u002F02.agents\u002Findex",[342,343,347,351,355,359],{"title":338,"path":339,"stem":340},{"title":344,"path":345,"stem":346},"Listar agentes","\u002Fpt\u002Fapi\u002Freference\u002Fagents\u002Flist-agents","pt\u002F12.api\u002F07.reference\u002F02.agents\u002F01.list-agents",{"title":348,"path":349,"stem":350},"Ver um agente","\u002Fpt\u002Fapi\u002Freference\u002Fagents\u002Fget-agent","pt\u002F12.api\u002F07.reference\u002F02.agents\u002F02.get-agent",{"title":352,"path":353,"stem":354},"Editar um agente","\u002Fpt\u002Fapi\u002Freference\u002Fagents\u002Fupdate-agent","pt\u002F12.api\u002F07.reference\u002F02.agents\u002F03.update-agent",{"title":356,"path":357,"stem":358},"Criar um agente","\u002Fpt\u002Fapi\u002Freference\u002Fagents\u002Fcreate-agent","pt\u002F12.api\u002F07.reference\u002F02.agents\u002F04.create-agent",{"title":360,"path":361,"stem":362},"Publicar um agente","\u002Fpt\u002Fapi\u002Freference\u002Fagents\u002Fpublish-agent","pt\u002F12.api\u002F07.reference\u002F02.agents\u002F05.publish-agent",{"title":258,"path":364,"stem":365,"children":366},"\u002Fpt\u002Fapi\u002Freference\u002Fcalls","pt\u002F12.api\u002F07.reference\u002F03.calls\u002Findex",[367,368,372,376],{"title":258,"path":364,"stem":365},{"title":369,"path":370,"stem":371},"Listar chamadas","\u002Fpt\u002Fapi\u002Freference\u002Fcalls\u002Flist-calls","pt\u002F12.api\u002F07.reference\u002F03.calls\u002F01.list-calls",{"title":373,"path":374,"stem":375},"Ver uma chamada","\u002Fpt\u002Fapi\u002Freference\u002Fcalls\u002Fget-call","pt\u002F12.api\u002F07.reference\u002F03.calls\u002F02.get-call",{"title":377,"path":378,"stem":379},"Descarregar a gravação","\u002Fpt\u002Fapi\u002Freference\u002Fcalls\u002Fget-call-recording","pt\u002F12.api\u002F07.reference\u002F03.calls\u002F03.get-call-recording",{"title":381,"path":382,"stem":383,"children":384},"Chamadas de saída","\u002Fpt\u002Fapi\u002Freference\u002Foutbound-calls","pt\u002F12.api\u002F07.reference\u002F04.outbound-calls\u002Findex",[385,386,390,394],{"title":381,"path":382,"stem":383},{"title":387,"path":388,"stem":389},"Fazer uma chamada de saída","\u002Fpt\u002Fapi\u002Freference\u002Foutbound-calls\u002Fcreate-outbound-call","pt\u002F12.api\u002F07.reference\u002F04.outbound-calls\u002F01.create-outbound-call",{"title":391,"path":392,"stem":393},"Ver uma chamada de saída","\u002Fpt\u002Fapi\u002Freference\u002Foutbound-calls\u002Fget-outbound-call","pt\u002F12.api\u002F07.reference\u002F04.outbound-calls\u002F02.get-outbound-call",{"title":395,"path":396,"stem":397},"Desligar uma chamada de saída","\u002Fpt\u002Fapi\u002Freference\u002Foutbound-calls\u002Fhang-up-outbound-call","pt\u002F12.api\u002F07.reference\u002F04.outbound-calls\u002F03.hang-up-outbound-call",{"title":399,"path":400,"stem":401,"children":402},"Campanhas","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002Findex",[403,404,408,412,416,420,424,428,432,436],{"title":399,"path":400,"stem":401},{"title":405,"path":406,"stem":407},"Listar campanhas","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Flist-campaigns","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F01.list-campaigns",{"title":409,"path":410,"stem":411},"Criar uma campanha","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Fcreate-campaign","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F02.create-campaign",{"title":413,"path":414,"stem":415},"Ver uma campanha","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Fget-campaign","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F03.get-campaign",{"title":417,"path":418,"stem":419},"Acrescentar destinatários","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Fadd-campaign-recipients","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F04.add-campaign-recipients",{"title":421,"path":422,"stem":423},"Listar destinatários","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Flist-campaign-recipients","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F05.list-campaign-recipients",{"title":425,"path":426,"stem":427},"Iniciar uma campanha","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Fstart-campaign","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F06.start-campaign",{"title":429,"path":430,"stem":431},"Pausar uma campanha","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Fpause-campaign","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F07.pause-campaign",{"title":433,"path":434,"stem":435},"Retomar uma campanha","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Fresume-campaign","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F08.resume-campaign",{"title":437,"path":438,"stem":439},"Cancelar uma campanha","\u002Fpt\u002Fapi\u002Freference\u002Fcampaigns\u002Fcancel-campaign","pt\u002F12.api\u002F07.reference\u002F05.campaigns\u002F09.cancel-campaign",{"title":441,"path":442,"stem":443,"children":444},"Chat","\u002Fpt\u002Fapi\u002Freference\u002Fchats","pt\u002F12.api\u002F07.reference\u002F06.chats\u002Findex",[445,446,450,454,458,462],{"title":441,"path":442,"stem":443},{"title":447,"path":448,"stem":449},"Criar uma conversa","\u002Fpt\u002Fapi\u002Freference\u002Fchats\u002Fcreate-chat","pt\u002F12.api\u002F07.reference\u002F06.chats\u002F01.create-chat",{"title":451,"path":452,"stem":453},"Enviar uma mensagem","\u002Fpt\u002Fapi\u002Freference\u002Fchats\u002Fsend-chat-message","pt\u002F12.api\u002F07.reference\u002F06.chats\u002F02.send-chat-message",{"title":455,"path":456,"stem":457},"Ver uma conversa","\u002Fpt\u002Fapi\u002Freference\u002Fchats\u002Fget-chat","pt\u002F12.api\u002F07.reference\u002F06.chats\u002F03.get-chat",{"title":459,"path":460,"stem":461},"Listar conversas","\u002Fpt\u002Fapi\u002Freference\u002Fchats\u002Flist-chats","pt\u002F12.api\u002F07.reference\u002F06.chats\u002F04.list-chats",{"title":463,"path":464,"stem":465},"Terminar uma conversa","\u002Fpt\u002Fapi\u002Freference\u002Fchats\u002Fend-chat","pt\u002F12.api\u002F07.reference\u002F06.chats\u002F05.end-chat",{"title":266,"path":467,"stem":468,"children":469},"\u002Fpt\u002Fapi\u002Freference\u002Fanalytics","pt\u002F12.api\u002F07.reference\u002F07.analytics\u002Findex",[470,471],{"title":266,"path":467,"stem":468},{"title":472,"path":473,"stem":474},"Resumo das análises","\u002Fpt\u002Fapi\u002Freference\u002Fanalytics\u002Fget-overview","pt\u002F12.api\u002F07.reference\u002F07.analytics\u002F01.get-overview",{"title":476,"path":477,"stem":478,"children":479},"Números","\u002Fpt\u002Fapi\u002Freference\u002Fphone-numbers","pt\u002F12.api\u002F07.reference\u002F08.phone-numbers\u002Findex",[480,481],{"title":476,"path":477,"stem":478},{"title":482,"path":483,"stem":484},"Listar números","\u002Fpt\u002Fapi\u002Freference\u002Fphone-numbers\u002Flist-phone-numbers","pt\u002F12.api\u002F07.reference\u002F08.phone-numbers\u002F01.list-phone-numbers",{"title":486,"path":487,"stem":488,"children":489},"Conhecimento","\u002Fpt\u002Fapi\u002Freference\u002Fknowledge","pt\u002F12.api\u002F07.reference\u002F09.knowledge\u002Findex",[490,491,495,499,503,507],{"title":486,"path":487,"stem":488},{"title":492,"path":493,"stem":494},"Listar bases de conhecimento","\u002Fpt\u002Fapi\u002Freference\u002Fknowledge\u002Flist-knowledge-bases","pt\u002F12.api\u002F07.reference\u002F09.knowledge\u002F01.list-knowledge-bases",{"title":496,"path":497,"stem":498},"Criar uma base de conhecimento","\u002Fpt\u002Fapi\u002Freference\u002Fknowledge\u002Fcreate-knowledge-base","pt\u002F12.api\u002F07.reference\u002F09.knowledge\u002F02.create-knowledge-base",{"title":500,"path":501,"stem":502},"Adicionar um documento de texto","\u002Fpt\u002Fapi\u002Freference\u002Fknowledge\u002Fadd-text-document","pt\u002F12.api\u002F07.reference\u002F09.knowledge\u002F03.add-text-document",{"title":504,"path":505,"stem":506},"Importar uma página web","\u002Fpt\u002Fapi\u002Freference\u002Fknowledge\u002Fimport-url","pt\u002F12.api\u002F07.reference\u002F09.knowledge\u002F04.import-url",{"title":508,"path":509,"stem":510},"Carregar um PDF","\u002Fpt\u002Fapi\u002Freference\u002Fknowledge\u002Fupload-pdf","pt\u002F12.api\u002F07.reference\u002F09.knowledge\u002F05.upload-pdf",{"title":310,"path":512,"stem":513,"children":514},"\u002Fpt\u002Fapi\u002Freference\u002Fwebhooks","pt\u002F12.api\u002F07.reference\u002F10.webhooks\u002Findex",[515,516,520,524,528,532],{"title":310,"path":512,"stem":513},{"title":517,"path":518,"stem":519},"Listar endpoints de webhook","\u002Fpt\u002Fapi\u002Freference\u002Fwebhooks\u002Flist-webhook-endpoints","pt\u002F12.api\u002F07.reference\u002F10.webhooks\u002F01.list-webhook-endpoints",{"title":521,"path":522,"stem":523},"Registar um endpoint de webhook","\u002Fpt\u002Fapi\u002Freference\u002Fwebhooks\u002Fcreate-webhook-endpoint","pt\u002F12.api\u002F07.reference\u002F10.webhooks\u002F02.create-webhook-endpoint",{"title":525,"path":526,"stem":527},"Alterar um endpoint de webhook","\u002Fpt\u002Fapi\u002Freference\u002Fwebhooks\u002Fupdate-webhook-endpoint","pt\u002F12.api\u002F07.reference\u002F10.webhooks\u002F03.update-webhook-endpoint",{"title":529,"path":530,"stem":531},"Remover um endpoint de webhook","\u002Fpt\u002Fapi\u002Freference\u002Fwebhooks\u002Fdelete-webhook-endpoint","pt\u002F12.api\u002F07.reference\u002F10.webhooks\u002F04.delete-webhook-endpoint",{"title":533,"path":534,"stem":535},"Testar um endpoint de webhook","\u002Fpt\u002Fapi\u002Freference\u002Fwebhooks\u002Ftest-webhook-endpoint","pt\u002F12.api\u002F07.reference\u002F10.webhooks\u002F05.test-webhook-endpoint",{"title":537,"path":538,"stem":539,"children":540},"Guias da API","\u002Fpt\u002Fapi\u002Fguides","pt\u002F12.api\u002F08.guides\u002Findex",[541,542,546,550],{"title":537,"path":538,"stem":539},{"title":543,"path":544,"stem":545},"Sincronizar chamadas com o CRM","\u002Fpt\u002Fapi\u002Fguides\u002Fsync-calls-crm","pt\u002F12.api\u002F08.guides\u002F01.sync-calls-crm",{"title":547,"path":548,"stem":549},"Exportar o histórico de chamadas","\u002Fpt\u002Fapi\u002Fguides\u002Fexport-call-history","pt\u002F12.api\u002F08.guides\u002F02.export-call-history",{"title":551,"path":552,"stem":553},"Alimentar o conhecimento a partir do site","\u002Fpt\u002Fapi\u002Fguides\u002Fknowledge-from-website","pt\u002F12.api\u002F08.guides\u002F03.knowledge-from-website",{"title":555,"path":556,"stem":557},"Versões e alterações","\u002Fpt\u002Fapi\u002Fchangelog","pt\u002F12.api\u002F09.changelog",{"title":559,"path":560,"stem":561},"OAuth para plataformas parceiras","\u002Fpt\u002Fapi\u002Foauth","pt\u002F12.api\u002F10.oauth",{"title":563,"path":564,"stem":565,"children":566},"Integrações","\u002Fpt\u002Fintegrations","pt\u002F13.integrations\u002Findex",[567,568],{"title":563,"path":564,"stem":565},{"title":569,"path":570,"stem":571},"Cal.com","\u002Fpt\u002Fintegrations\u002Fcalcom","pt\u002F13.integrations\u002F01.calcom",{"title":573,"path":574,"stem":575,"children":576},"Telefonia","\u002Fpt\u002Ftelephony","pt\u002F14.telephony\u002Findex",[577,578,582,586,590,594,597,601,605,609],{"title":573,"path":574,"stem":575},{"title":579,"path":580,"stem":581},"Números de telefone","\u002Fpt\u002Ftelephony\u002Fnumbers","pt\u002F14.telephony\u002F01.numbers",{"title":583,"path":584,"stem":585},"Ligar por SIP","\u002Fpt\u002Ftelephony\u002Fsip-trunk","pt\u002F14.telephony\u002F02.sip-trunk",{"title":587,"path":588,"stem":589},"Chamadas telefónicas","\u002Fpt\u002Ftelephony\u002Fphone-calls","pt\u002F14.telephony\u002F03.phone-calls",{"title":591,"path":592,"stem":593},"Configuração de chamada","\u002Fpt\u002Ftelephony\u002Fcall-settings","pt\u002F14.telephony\u002F04.call-settings",{"title":399,"path":595,"stem":596},"\u002Fpt\u002Ftelephony\u002Fcampaigns","pt\u002F14.telephony\u002F05.campaigns",{"title":598,"path":599,"stem":600},"Chamadas em simultâneo","\u002Fpt\u002Ftelephony\u002Fconcurrency","pt\u002F14.telephony\u002F06.concurrency",{"title":602,"path":603,"stem":604},"Transferências","\u002Fpt\u002Ftelephony\u002Ftransfers","pt\u002F14.telephony\u002F07.transfers",{"title":606,"path":607,"stem":608},"Webhooks do agente","\u002Fpt\u002Ftelephony\u002Fwebhooks","pt\u002F14.telephony\u002F08.webhooks",{"title":610,"path":611,"stem":612},"Erros e motivos de fim","\u002Fpt\u002Ftelephony\u002Ferrors","pt\u002F14.telephony\u002F09.errors",{"title":614,"path":615,"stem":616,"children":617},"Definições","\u002Fpt\u002Fsettings","pt\u002F15.settings\u002Findex",[618,619,623,627,631,635,639,643,647,651,654,658],{"title":614,"path":615,"stem":616},{"title":620,"path":621,"stem":622},"Perfil","\u002Fpt\u002Fsettings\u002Fpersonal-profile","pt\u002F15.settings\u002F01.personal-profile",{"title":624,"path":625,"stem":626},"Credenciais","\u002Fpt\u002Fsettings\u002Fcredentials","pt\u002F15.settings\u002F02.credentials",{"title":628,"path":629,"stem":630},"Password","\u002Fpt\u002Fsettings\u002Fpassword","pt\u002F15.settings\u002F03.password",{"title":632,"path":633,"stem":634},"Autenticação de dois fatores","\u002Fpt\u002Fsettings\u002Ftwo-factor","pt\u002F15.settings\u002F04.two-factor",{"title":636,"path":637,"stem":638},"Sessões ativas","\u002Fpt\u002Fsettings\u002Fsessions","pt\u002F15.settings\u002F05.sessions",{"title":640,"path":641,"stem":642},"Empresa","\u002Fpt\u002Fsettings\u002Fcompany","pt\u002F15.settings\u002F06.company",{"title":644,"path":645,"stem":646},"Organização","\u002Fpt\u002Fsettings\u002Forganization","pt\u002F15.settings\u002F07.organization",{"title":648,"path":649,"stem":650},"Membros","\u002Fpt\u002Fsettings\u002Fmembers","pt\u002F15.settings\u002F08.members",{"title":563,"path":652,"stem":653},"\u002Fpt\u002Fsettings\u002Fintegrations","pt\u002F15.settings\u002F09.integrations",{"title":655,"path":656,"stem":657},"Chaves API","\u002Fpt\u002Fsettings\u002Fapi-keys","pt\u002F15.settings\u002F10.api-keys",{"title":659,"path":660,"stem":661},"Aplicações ligadas e Apps OAuth","\u002Fpt\u002Fsettings\u002Fconnected-apps","pt\u002F15.settings\u002F11.connected-apps",{"title":663,"path":664,"stem":665,"children":666},"Problemas frequentes","\u002Fpt\u002Ftroubleshooting","pt\u002F16.troubleshooting\u002Findex",[667,668,672,676,680,684,688],{"title":663,"path":664,"stem":665},{"title":669,"path":670,"stem":671},"Agente não atende","\u002Fpt\u002Ftroubleshooting\u002Fagent-not-answering","pt\u002F16.troubleshooting\u002F01.agent-not-answering",{"title":673,"path":674,"stem":675},"Chamadas caem","\u002Fpt\u002Ftroubleshooting\u002Fcalls-drop","pt\u002F16.troubleshooting\u002F02.calls-drop",{"title":677,"path":678,"stem":679},"Fluxo não publica","\u002Fpt\u002Ftroubleshooting\u002Fflow-not-publishing","pt\u002F16.troubleshooting\u002F03.flow-not-publishing",{"title":681,"path":682,"stem":683},"Conhecimento não responde","\u002Fpt\u002Ftroubleshooting\u002Fkb-not-answering","pt\u002F16.troubleshooting\u002F04.kb-not-answering",{"title":685,"path":686,"stem":687},"Integração não liga","\u002Fpt\u002Ftroubleshooting\u002Fintegration-not-connecting","pt\u002F16.troubleshooting\u002F05.integration-not-connecting",{"title":689,"path":690,"stem":691},"Testes falham","\u002Fpt\u002Ftroubleshooting\u002Ftests-failing","pt\u002F16.troubleshooting\u002F06.tests-failing",{"title":693,"path":694,"stem":695,"children":696,"page":705},"Legal","\u002Fpt\u002Flegal","pt\u002F17.legal",[697,701],{"title":698,"path":699,"stem":700},"Política de Privacidade","\u002Fpt\u002Flegal\u002Fprivacy","pt\u002F17.legal\u002F01.privacy",{"title":702,"path":703,"stem":704},"Termos e Condições","\u002Fpt\u002Flegal\u002Fterms","pt\u002F17.legal\u002F02.terms",false,{"id":707,"title":543,"body":708,"description":3254,"extension":3255,"links":3256,"meta":3257,"navigation":855,"path":544,"seo":3258,"stem":545,"__hash__":3259},"docs_pt\u002Fpt\u002F12.api\u002F08.guides\u002F01.sync-calls-crm.md",{"type":709,"value":710,"toc":3246},"minimark",[711,720,736,739,744,789,793,2696,2699,2765,2775,2784,2838,2841,2845,2911,2930,2934,2979,2996,3002,3006,3015,3198,3205,3209,3242],[712,713,714,715,719],"p",{},"Neste guia, cada chamada concluída chega ao seu servidor por ",[716,717,718],"a",{"href":311},"webhook",", sem polling. O receptor:",[721,722,723,727,730,733],"ol",{},[724,725,726],"li",{},"verifica a assinatura;",[724,728,729],{},"ignora repetições;",[724,731,732],{},"responde logo;",[724,734,735],{},"numa fila, lê o detalhe da chamada e cria ou actualiza o contacto e a actividade no CRM.",[712,737,738],{},"Uma reconciliação diária apanha o que se tenha perdido.",[740,741,743],"h2",{"id":742},"antes-de-começar","Antes de começar",[745,746,747,771,778],"ul",{},[724,748,749,750,753,754,758,759,763,764,758,767,770],{},"Uma ",[716,751,752],{"href":307},"chave API"," com os âmbitos ",[755,756,757],"strong",{},"Webhooks — gestão"," (",[760,761,762],"code",{},"webhooks:manage",") e ",[755,765,766],{},"Chamadas e transcrições",[760,768,769],{},"calls:read",").",[724,772,773,774,777],{},"Um servidor acessível da internet por ",[760,775,776],{},"https:\u002F\u002F",".",[724,779,780,781,784,785,788],{},"Python 3.11 ou superior com ",[760,782,783],{},"flask"," e ",[760,786,787],{},"requests",", ou Node.js 18 ou superior.",[740,790,792],{"id":791},"_1-escreva-o-receptor","1. Escreva o receptor",[794,795,796,1298],"code-group",{},[797,798,804],"pre",{"className":799,"code":800,"filename":801,"language":802,"meta":803,"style":803},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import hashlib\nimport hmac\nimport json\nimport os\nimport queue\nimport threading\nimport time\n\nimport requests\nfrom flask import Flask, request\n\nAPI = \"https:\u002F\u002Fapi.diska.ai\u002Fv1\"\nAPI_KEY = os.environ[\"DISKA_API_KEY\"]\nSECRET = os.environ[\"DISKA_WEBHOOK_SECRET\"]\n\napp = Flask(__name__)\njobs: queue.Queue = queue.Queue()\nseen: set[str] = set()  # em produção: uma tabela com X-Diska-Delivery como chave única\n\n\ndef is_valid(timestamp: str, body: bytes, signature: str) -> bool:\n    if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > 300:\n        return False\n    expected = hmac.new(SECRET.encode(), f\"{timestamp}.\".encode() + body, hashlib.sha256).hexdigest()\n    return hmac.compare_digest(f\"sha256={expected}\", signature)\n\n\n@app.post(\"\u002Fhooks\u002Fdiska\")\ndef receive():\n    body = request.get_data()  # o corpo bruto, antes de interpretar o JSON\n    timestamp = request.headers.get(\"X-Diska-Timestamp\", \"\")\n    if not is_valid(timestamp, body, request.headers.get(\"X-Diska-Signature\", \"\")):\n        return \"\", 401\n    delivery = request.headers.get(\"X-Diska-Delivery\", \"\")\n    if delivery in seen:\n        return \"\", 200  # repetição de uma entrega que já recebeu\n    seen.add(delivery)\n    event = json.loads(body)\n    if event.get(\"event\") == \"call.completed\":\n        jobs.put(event)  # processe fora do pedido: responda em menos de 10 segundos\n    return \"\", 200\n\n\ndef crm_upsert(phone: str | None, name: str | None, activity: dict) -> None:\n    # Substitua pela chamada à API do seu CRM: procure o contacto pelo telefone,\n    # crie-o se não existir e acrescente a actividade com o id da chamada.\n    print(\"CRM\", phone, name, activity)\n\n\ndef sync_call(event: dict) -> None:\n    response = requests.get(\n        f\"{API}\u002Fcalls\u002F{event['call_id']}\",\n        headers={\"Authorization\": f\"Bearer {API_KEY}\"},\n        timeout=30,\n    )\n    response.raise_for_status()\n    call = response.json()\n    crm_upsert(\n        phone=event.get(\"caller_contact\"),\n        name=call.get(\"caller_name\"),\n        activity={\n            \"diska_call_id\": call[\"id\"],\n            \"started_at\": call[\"started_at\"],\n            \"duration_seconds\": call[\"duration_seconds\"],\n            \"agent\": call[\"agent_name\"],\n            \"summary\": call[\"summary\"],\n            \"sentiment\": event.get(\"sentiment\"),\n            \"data\": event.get(\"extracted_data\", {}),\n        },\n    )\n\n\ndef worker() -> None:\n    while True:\n        event = jobs.get()\n        try:\n            sync_call(event)\n        except Exception as exc:  # a reconciliação diária apanha o que falhar aqui\n            print(\"sincronização falhou\", event[\"call_id\"], exc)\n        finally:\n            jobs.task_done()\n\n\nthreading.Thread(target=worker, daemon=True).start()\n","Python","python","",[760,805,806,814,820,826,832,838,844,850,857,863,869,874,880,886,892,897,903,909,915,920,925,931,937,943,949,955,960,965,971,977,983,989,995,1001,1007,1013,1019,1025,1031,1037,1043,1049,1054,1059,1065,1071,1077,1083,1088,1093,1099,1105,1111,1117,1123,1129,1135,1141,1147,1153,1159,1165,1171,1177,1183,1189,1195,1201,1207,1213,1218,1223,1228,1234,1240,1246,1252,1258,1264,1270,1276,1282,1287,1292],{"__ignoreMap":803},[807,808,811],"span",{"class":809,"line":810},"line",1,[807,812,813],{},"import hashlib\n",[807,815,817],{"class":809,"line":816},2,[807,818,819],{},"import hmac\n",[807,821,823],{"class":809,"line":822},3,[807,824,825],{},"import json\n",[807,827,829],{"class":809,"line":828},4,[807,830,831],{},"import os\n",[807,833,835],{"class":809,"line":834},5,[807,836,837],{},"import queue\n",[807,839,841],{"class":809,"line":840},6,[807,842,843],{},"import threading\n",[807,845,847],{"class":809,"line":846},7,[807,848,849],{},"import time\n",[807,851,853],{"class":809,"line":852},8,[807,854,856],{"emptyLinePlaceholder":855},true,"\n",[807,858,860],{"class":809,"line":859},9,[807,861,862],{},"import requests\n",[807,864,866],{"class":809,"line":865},10,[807,867,868],{},"from flask import Flask, request\n",[807,870,872],{"class":809,"line":871},11,[807,873,856],{"emptyLinePlaceholder":855},[807,875,877],{"class":809,"line":876},12,[807,878,879],{},"API = \"https:\u002F\u002Fapi.diska.ai\u002Fv1\"\n",[807,881,883],{"class":809,"line":882},13,[807,884,885],{},"API_KEY = os.environ[\"DISKA_API_KEY\"]\n",[807,887,889],{"class":809,"line":888},14,[807,890,891],{},"SECRET = os.environ[\"DISKA_WEBHOOK_SECRET\"]\n",[807,893,895],{"class":809,"line":894},15,[807,896,856],{"emptyLinePlaceholder":855},[807,898,900],{"class":809,"line":899},16,[807,901,902],{},"app = Flask(__name__)\n",[807,904,906],{"class":809,"line":905},17,[807,907,908],{},"jobs: queue.Queue = queue.Queue()\n",[807,910,912],{"class":809,"line":911},18,[807,913,914],{},"seen: set[str] = set()  # em produção: uma tabela com X-Diska-Delivery como chave única\n",[807,916,918],{"class":809,"line":917},19,[807,919,856],{"emptyLinePlaceholder":855},[807,921,923],{"class":809,"line":922},20,[807,924,856],{"emptyLinePlaceholder":855},[807,926,928],{"class":809,"line":927},21,[807,929,930],{},"def is_valid(timestamp: str, body: bytes, signature: str) -> bool:\n",[807,932,934],{"class":809,"line":933},22,[807,935,936],{},"    if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > 300:\n",[807,938,940],{"class":809,"line":939},23,[807,941,942],{},"        return False\n",[807,944,946],{"class":809,"line":945},24,[807,947,948],{},"    expected = hmac.new(SECRET.encode(), f\"{timestamp}.\".encode() + body, hashlib.sha256).hexdigest()\n",[807,950,952],{"class":809,"line":951},25,[807,953,954],{},"    return hmac.compare_digest(f\"sha256={expected}\", signature)\n",[807,956,958],{"class":809,"line":957},26,[807,959,856],{"emptyLinePlaceholder":855},[807,961,963],{"class":809,"line":962},27,[807,964,856],{"emptyLinePlaceholder":855},[807,966,968],{"class":809,"line":967},28,[807,969,970],{},"@app.post(\"\u002Fhooks\u002Fdiska\")\n",[807,972,974],{"class":809,"line":973},29,[807,975,976],{},"def receive():\n",[807,978,980],{"class":809,"line":979},30,[807,981,982],{},"    body = request.get_data()  # o corpo bruto, antes de interpretar o JSON\n",[807,984,986],{"class":809,"line":985},31,[807,987,988],{},"    timestamp = request.headers.get(\"X-Diska-Timestamp\", \"\")\n",[807,990,992],{"class":809,"line":991},32,[807,993,994],{},"    if not is_valid(timestamp, body, request.headers.get(\"X-Diska-Signature\", \"\")):\n",[807,996,998],{"class":809,"line":997},33,[807,999,1000],{},"        return \"\", 401\n",[807,1002,1004],{"class":809,"line":1003},34,[807,1005,1006],{},"    delivery = request.headers.get(\"X-Diska-Delivery\", \"\")\n",[807,1008,1010],{"class":809,"line":1009},35,[807,1011,1012],{},"    if delivery in seen:\n",[807,1014,1016],{"class":809,"line":1015},36,[807,1017,1018],{},"        return \"\", 200  # repetição de uma entrega que já recebeu\n",[807,1020,1022],{"class":809,"line":1021},37,[807,1023,1024],{},"    seen.add(delivery)\n",[807,1026,1028],{"class":809,"line":1027},38,[807,1029,1030],{},"    event = json.loads(body)\n",[807,1032,1034],{"class":809,"line":1033},39,[807,1035,1036],{},"    if event.get(\"event\") == \"call.completed\":\n",[807,1038,1040],{"class":809,"line":1039},40,[807,1041,1042],{},"        jobs.put(event)  # processe fora do pedido: responda em menos de 10 segundos\n",[807,1044,1046],{"class":809,"line":1045},41,[807,1047,1048],{},"    return \"\", 200\n",[807,1050,1052],{"class":809,"line":1051},42,[807,1053,856],{"emptyLinePlaceholder":855},[807,1055,1057],{"class":809,"line":1056},43,[807,1058,856],{"emptyLinePlaceholder":855},[807,1060,1062],{"class":809,"line":1061},44,[807,1063,1064],{},"def crm_upsert(phone: str | None, name: str | None, activity: dict) -> None:\n",[807,1066,1068],{"class":809,"line":1067},45,[807,1069,1070],{},"    # Substitua pela chamada à API do seu CRM: procure o contacto pelo telefone,\n",[807,1072,1074],{"class":809,"line":1073},46,[807,1075,1076],{},"    # crie-o se não existir e acrescente a actividade com o id da chamada.\n",[807,1078,1080],{"class":809,"line":1079},47,[807,1081,1082],{},"    print(\"CRM\", phone, name, activity)\n",[807,1084,1086],{"class":809,"line":1085},48,[807,1087,856],{"emptyLinePlaceholder":855},[807,1089,1091],{"class":809,"line":1090},49,[807,1092,856],{"emptyLinePlaceholder":855},[807,1094,1096],{"class":809,"line":1095},50,[807,1097,1098],{},"def sync_call(event: dict) -> None:\n",[807,1100,1102],{"class":809,"line":1101},51,[807,1103,1104],{},"    response = requests.get(\n",[807,1106,1108],{"class":809,"line":1107},52,[807,1109,1110],{},"        f\"{API}\u002Fcalls\u002F{event['call_id']}\",\n",[807,1112,1114],{"class":809,"line":1113},53,[807,1115,1116],{},"        headers={\"Authorization\": f\"Bearer {API_KEY}\"},\n",[807,1118,1120],{"class":809,"line":1119},54,[807,1121,1122],{},"        timeout=30,\n",[807,1124,1126],{"class":809,"line":1125},55,[807,1127,1128],{},"    )\n",[807,1130,1132],{"class":809,"line":1131},56,[807,1133,1134],{},"    response.raise_for_status()\n",[807,1136,1138],{"class":809,"line":1137},57,[807,1139,1140],{},"    call = response.json()\n",[807,1142,1144],{"class":809,"line":1143},58,[807,1145,1146],{},"    crm_upsert(\n",[807,1148,1150],{"class":809,"line":1149},59,[807,1151,1152],{},"        phone=event.get(\"caller_contact\"),\n",[807,1154,1156],{"class":809,"line":1155},60,[807,1157,1158],{},"        name=call.get(\"caller_name\"),\n",[807,1160,1162],{"class":809,"line":1161},61,[807,1163,1164],{},"        activity={\n",[807,1166,1168],{"class":809,"line":1167},62,[807,1169,1170],{},"            \"diska_call_id\": call[\"id\"],\n",[807,1172,1174],{"class":809,"line":1173},63,[807,1175,1176],{},"            \"started_at\": call[\"started_at\"],\n",[807,1178,1180],{"class":809,"line":1179},64,[807,1181,1182],{},"            \"duration_seconds\": call[\"duration_seconds\"],\n",[807,1184,1186],{"class":809,"line":1185},65,[807,1187,1188],{},"            \"agent\": call[\"agent_name\"],\n",[807,1190,1192],{"class":809,"line":1191},66,[807,1193,1194],{},"            \"summary\": call[\"summary\"],\n",[807,1196,1198],{"class":809,"line":1197},67,[807,1199,1200],{},"            \"sentiment\": event.get(\"sentiment\"),\n",[807,1202,1204],{"class":809,"line":1203},68,[807,1205,1206],{},"            \"data\": event.get(\"extracted_data\", {}),\n",[807,1208,1210],{"class":809,"line":1209},69,[807,1211,1212],{},"        },\n",[807,1214,1216],{"class":809,"line":1215},70,[807,1217,1128],{},[807,1219,1221],{"class":809,"line":1220},71,[807,1222,856],{"emptyLinePlaceholder":855},[807,1224,1226],{"class":809,"line":1225},72,[807,1227,856],{"emptyLinePlaceholder":855},[807,1229,1231],{"class":809,"line":1230},73,[807,1232,1233],{},"def worker() -> None:\n",[807,1235,1237],{"class":809,"line":1236},74,[807,1238,1239],{},"    while True:\n",[807,1241,1243],{"class":809,"line":1242},75,[807,1244,1245],{},"        event = jobs.get()\n",[807,1247,1249],{"class":809,"line":1248},76,[807,1250,1251],{},"        try:\n",[807,1253,1255],{"class":809,"line":1254},77,[807,1256,1257],{},"            sync_call(event)\n",[807,1259,1261],{"class":809,"line":1260},78,[807,1262,1263],{},"        except Exception as exc:  # a reconciliação diária apanha o que falhar aqui\n",[807,1265,1267],{"class":809,"line":1266},79,[807,1268,1269],{},"            print(\"sincronização falhou\", event[\"call_id\"], exc)\n",[807,1271,1273],{"class":809,"line":1272},80,[807,1274,1275],{},"        finally:\n",[807,1277,1279],{"class":809,"line":1278},81,[807,1280,1281],{},"            jobs.task_done()\n",[807,1283,1285],{"class":809,"line":1284},82,[807,1286,856],{"emptyLinePlaceholder":855},[807,1288,1290],{"class":809,"line":1289},83,[807,1291,856],{"emptyLinePlaceholder":855},[807,1293,1295],{"class":809,"line":1294},84,[807,1296,1297],{},"threading.Thread(target=worker, daemon=True).start()\n",[797,1299,1304],{"className":1300,"code":1301,"filename":1302,"language":1303,"meta":803,"style":803},"language-js shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F Node.js 18 ou superior, num ficheiro .mjs\nimport crypto from 'node:crypto'\nimport http from 'node:http'\n\nconst API = 'https:\u002F\u002Fapi.diska.ai\u002Fv1'\nconst { DISKA_API_KEY, DISKA_WEBHOOK_SECRET } = process.env\nconst seen = new Set() \u002F\u002F em produção: uma tabela com X-Diska-Delivery como chave única\n\nfunction isValid(timestamp, rawBody, signature) {\n  if (!\u002F^\\d+$\u002F.test(timestamp || '') || Math.abs(Date.now() \u002F 1000 - Number(timestamp)) > 300) return false\n  const expected = 'sha256=' + crypto.createHmac('sha256', DISKA_WEBHOOK_SECRET)\n    .update(`${timestamp}.`).update(rawBody).digest('hex')\n  const a = Buffer.from(expected)\n  const b = Buffer.from(signature || '')\n  return a.length === b.length && crypto.timingSafeEqual(a, b)\n}\n\nasync function crmUpsert(phone, name, activity) {\n  \u002F\u002F Substitua pela chamada à API do seu CRM: procure o contacto pelo telefone,\n  \u002F\u002F crie-o se não existir e acrescente a actividade com o id da chamada.\n  console.log('CRM', phone, name, activity)\n}\n\nasync function syncCall(event) {\n  const response = await fetch(`${API}\u002Fcalls\u002F${event.call_id}`, {\n    headers: { Authorization: `Bearer ${DISKA_API_KEY}` }\n  })\n  if (!response.ok) throw new Error(`HTTP ${response.status}`)\n  const call = await response.json()\n  await crmUpsert(event.caller_contact, call.caller_name, {\n    diska_call_id: call.id,\n    started_at: call.started_at,\n    duration_seconds: call.duration_seconds,\n    agent: call.agent_name,\n    summary: call.summary,\n    sentiment: event.sentiment,\n    data: event.extracted_data ?? {}\n  })\n}\n\nhttp.createServer((req, res) => {\n  if (req.method !== 'POST' || req.url !== '\u002Fhooks\u002Fdiska') return res.writeHead(404).end()\n  const chunks = []\n  req.on('data', chunk => chunks.push(chunk))\n  req.on('end', () => {\n    const rawBody = Buffer.concat(chunks) \u002F\u002F o corpo bruto, antes de interpretar o JSON\n    if (!isValid(req.headers['x-diska-timestamp'], rawBody, req.headers['x-diska-signature'])) return res.writeHead(401).end()\n    res.writeHead(200).end() \u002F\u002F responda já; processe a seguir\n    const delivery = req.headers['x-diska-delivery']\n    if (seen.has(delivery)) return \u002F\u002F repetição de uma entrega que já recebeu\n    seen.add(delivery)\n    const event = JSON.parse(rawBody)\n    if (event.event === 'call.completed') {\n      syncCall(event).catch(err => console.error('sincronização falhou', event.call_id, err)) \u002F\u002F a reconciliação apanha o que falhar\n    }\n  })\n}).listen(Number(process.env.PORT || 3000))\n","Node.js","js",[760,1305,1306,1312,1336,1352,1356,1375,1405,1427,1431,1462,1565,1611,1662,1685,1711,1752,1757,1761,1791,1796,1801,1835,1839,1843,1861,1904,1935,1942,1988,2009,2038,2055,2071,2087,2103,2119,2136,2156,2162,2166,2170,2199,2266,2278,2319,2344,2370,2449,2474,2501,2527,2543,2565,2591,2649,2654,2660],{"__ignoreMap":803},[807,1307,1308],{"class":809,"line":810},[807,1309,1311],{"class":1310},"sHwdD","\u002F\u002F Node.js 18 ou superior, num ficheiro .mjs\n",[807,1313,1314,1318,1322,1325,1329,1333],{"class":809,"line":816},[807,1315,1317],{"class":1316},"s7zQu","import",[807,1319,1321],{"class":1320},"sTEyZ"," crypto ",[807,1323,1324],{"class":1316},"from",[807,1326,1328],{"class":1327},"sMK4o"," '",[807,1330,1332],{"class":1331},"sfazB","node:crypto",[807,1334,1335],{"class":1327},"'\n",[807,1337,1338,1340,1343,1345,1347,1350],{"class":809,"line":822},[807,1339,1317],{"class":1316},[807,1341,1342],{"class":1320}," http ",[807,1344,1324],{"class":1316},[807,1346,1328],{"class":1327},[807,1348,1349],{"class":1331},"node:http",[807,1351,1335],{"class":1327},[807,1353,1354],{"class":809,"line":828},[807,1355,856],{"emptyLinePlaceholder":855},[807,1357,1358,1362,1365,1368,1370,1373],{"class":809,"line":834},[807,1359,1361],{"class":1360},"spNyl","const",[807,1363,1364],{"class":1320}," API ",[807,1366,1367],{"class":1327},"=",[807,1369,1328],{"class":1327},[807,1371,1372],{"class":1331},"https:\u002F\u002Fapi.diska.ai\u002Fv1",[807,1374,1335],{"class":1327},[807,1376,1377,1379,1382,1385,1388,1391,1394,1397,1400,1402],{"class":809,"line":840},[807,1378,1361],{"class":1360},[807,1380,1381],{"class":1327}," {",[807,1383,1384],{"class":1320}," DISKA_API_KEY",[807,1386,1387],{"class":1327},",",[807,1389,1390],{"class":1320}," DISKA_WEBHOOK_SECRET ",[807,1392,1393],{"class":1327},"}",[807,1395,1396],{"class":1327}," =",[807,1398,1399],{"class":1320}," process",[807,1401,777],{"class":1327},[807,1403,1404],{"class":1320},"env\n",[807,1406,1407,1409,1412,1414,1417,1421,1424],{"class":809,"line":846},[807,1408,1361],{"class":1360},[807,1410,1411],{"class":1320}," seen ",[807,1413,1367],{"class":1327},[807,1415,1416],{"class":1327}," new",[807,1418,1420],{"class":1419},"s2Zo4"," Set",[807,1422,1423],{"class":1320},"() ",[807,1425,1426],{"class":1310},"\u002F\u002F em produção: uma tabela com X-Diska-Delivery como chave única\n",[807,1428,1429],{"class":809,"line":852},[807,1430,856],{"emptyLinePlaceholder":855},[807,1432,1433,1436,1439,1442,1446,1448,1451,1453,1456,1459],{"class":809,"line":859},[807,1434,1435],{"class":1360},"function",[807,1437,1438],{"class":1419}," isValid",[807,1440,1441],{"class":1327},"(",[807,1443,1445],{"class":1444},"sHdIc","timestamp",[807,1447,1387],{"class":1327},[807,1449,1450],{"class":1444}," rawBody",[807,1452,1387],{"class":1327},[807,1454,1455],{"class":1444}," signature",[807,1457,1458],{"class":1327},")",[807,1460,1461],{"class":1327}," {\n",[807,1463,1464,1467,1470,1473,1476,1479,1482,1485,1488,1490,1492,1495,1497,1499,1502,1505,1508,1511,1514,1516,1519,1521,1524,1526,1529,1531,1533,1537,1540,1543,1545,1547,1550,1553,1556,1558,1561],{"class":809,"line":865},[807,1465,1466],{"class":1316},"  if",[807,1468,758],{"class":1469},"swJcz",[807,1471,1472],{"class":1327},"!",[807,1474,1475],{"class":1327},"\u002F",[807,1477,1478],{"class":1316},"^",[807,1480,1481],{"class":1331},"\\d",[807,1483,1484],{"class":1327},"+",[807,1486,1487],{"class":1316},"$",[807,1489,1475],{"class":1327},[807,1491,777],{"class":1327},[807,1493,1494],{"class":1419},"test",[807,1496,1441],{"class":1469},[807,1498,1445],{"class":1320},[807,1500,1501],{"class":1327}," ||",[807,1503,1504],{"class":1327}," ''",[807,1506,1507],{"class":1469},") ",[807,1509,1510],{"class":1327},"||",[807,1512,1513],{"class":1320}," Math",[807,1515,777],{"class":1327},[807,1517,1518],{"class":1419},"abs",[807,1520,1441],{"class":1469},[807,1522,1523],{"class":1320},"Date",[807,1525,777],{"class":1327},[807,1527,1528],{"class":1419},"now",[807,1530,1423],{"class":1469},[807,1532,1475],{"class":1327},[807,1534,1536],{"class":1535},"sbssI"," 1000",[807,1538,1539],{"class":1327}," -",[807,1541,1542],{"class":1419}," Number",[807,1544,1441],{"class":1469},[807,1546,1445],{"class":1320},[807,1548,1549],{"class":1469},")) ",[807,1551,1552],{"class":1327},">",[807,1554,1555],{"class":1535}," 300",[807,1557,1507],{"class":1469},[807,1559,1560],{"class":1316},"return",[807,1562,1564],{"class":1563},"sfNiH"," false\n",[807,1566,1567,1570,1573,1575,1577,1580,1583,1586,1589,1591,1594,1596,1598,1601,1603,1605,1608],{"class":809,"line":871},[807,1568,1569],{"class":1360},"  const",[807,1571,1572],{"class":1320}," expected",[807,1574,1396],{"class":1327},[807,1576,1328],{"class":1327},[807,1578,1579],{"class":1331},"sha256=",[807,1581,1582],{"class":1327},"'",[807,1584,1585],{"class":1327}," +",[807,1587,1588],{"class":1320}," crypto",[807,1590,777],{"class":1327},[807,1592,1593],{"class":1419},"createHmac",[807,1595,1441],{"class":1469},[807,1597,1582],{"class":1327},[807,1599,1600],{"class":1331},"sha256",[807,1602,1582],{"class":1327},[807,1604,1387],{"class":1327},[807,1606,1607],{"class":1320}," DISKA_WEBHOOK_SECRET",[807,1609,1610],{"class":1469},")\n",[807,1612,1613,1616,1619,1621,1624,1626,1628,1630,1633,1635,1637,1639,1641,1644,1646,1648,1651,1653,1655,1658,1660],{"class":809,"line":876},[807,1614,1615],{"class":1327},"    .",[807,1617,1618],{"class":1419},"update",[807,1620,1441],{"class":1469},[807,1622,1623],{"class":1327},"`${",[807,1625,1445],{"class":1320},[807,1627,1393],{"class":1327},[807,1629,777],{"class":1331},[807,1631,1632],{"class":1327},"`",[807,1634,1458],{"class":1469},[807,1636,777],{"class":1327},[807,1638,1618],{"class":1419},[807,1640,1441],{"class":1469},[807,1642,1643],{"class":1320},"rawBody",[807,1645,1458],{"class":1469},[807,1647,777],{"class":1327},[807,1649,1650],{"class":1419},"digest",[807,1652,1441],{"class":1469},[807,1654,1582],{"class":1327},[807,1656,1657],{"class":1331},"hex",[807,1659,1582],{"class":1327},[807,1661,1610],{"class":1469},[807,1663,1664,1666,1669,1671,1674,1676,1678,1680,1683],{"class":809,"line":882},[807,1665,1569],{"class":1360},[807,1667,1668],{"class":1320}," a",[807,1670,1396],{"class":1327},[807,1672,1673],{"class":1320}," Buffer",[807,1675,777],{"class":1327},[807,1677,1324],{"class":1419},[807,1679,1441],{"class":1469},[807,1681,1682],{"class":1320},"expected",[807,1684,1610],{"class":1469},[807,1686,1687,1689,1692,1694,1696,1698,1700,1702,1705,1707,1709],{"class":809,"line":888},[807,1688,1569],{"class":1360},[807,1690,1691],{"class":1320}," b",[807,1693,1396],{"class":1327},[807,1695,1673],{"class":1320},[807,1697,777],{"class":1327},[807,1699,1324],{"class":1419},[807,1701,1441],{"class":1469},[807,1703,1704],{"class":1320},"signature",[807,1706,1501],{"class":1327},[807,1708,1504],{"class":1327},[807,1710,1610],{"class":1469},[807,1712,1713,1716,1718,1720,1723,1726,1728,1730,1732,1735,1737,1739,1742,1744,1746,1748,1750],{"class":809,"line":894},[807,1714,1715],{"class":1316},"  return",[807,1717,1668],{"class":1320},[807,1719,777],{"class":1327},[807,1721,1722],{"class":1320},"length",[807,1724,1725],{"class":1327}," ===",[807,1727,1691],{"class":1320},[807,1729,777],{"class":1327},[807,1731,1722],{"class":1320},[807,1733,1734],{"class":1327}," &&",[807,1736,1588],{"class":1320},[807,1738,777],{"class":1327},[807,1740,1741],{"class":1419},"timingSafeEqual",[807,1743,1441],{"class":1469},[807,1745,716],{"class":1320},[807,1747,1387],{"class":1327},[807,1749,1691],{"class":1320},[807,1751,1610],{"class":1469},[807,1753,1754],{"class":809,"line":899},[807,1755,1756],{"class":1327},"}\n",[807,1758,1759],{"class":809,"line":905},[807,1760,856],{"emptyLinePlaceholder":855},[807,1762,1763,1766,1769,1772,1774,1777,1779,1782,1784,1787,1789],{"class":809,"line":911},[807,1764,1765],{"class":1360},"async",[807,1767,1768],{"class":1360}," function",[807,1770,1771],{"class":1419}," crmUpsert",[807,1773,1441],{"class":1327},[807,1775,1776],{"class":1444},"phone",[807,1778,1387],{"class":1327},[807,1780,1781],{"class":1444}," name",[807,1783,1387],{"class":1327},[807,1785,1786],{"class":1444}," activity",[807,1788,1458],{"class":1327},[807,1790,1461],{"class":1327},[807,1792,1793],{"class":809,"line":917},[807,1794,1795],{"class":1310},"  \u002F\u002F Substitua pela chamada à API do seu CRM: procure o contacto pelo telefone,\n",[807,1797,1798],{"class":809,"line":922},[807,1799,1800],{"class":1310},"  \u002F\u002F crie-o se não existir e acrescente a actividade com o id da chamada.\n",[807,1802,1803,1806,1808,1811,1813,1815,1818,1820,1822,1825,1827,1829,1831,1833],{"class":809,"line":927},[807,1804,1805],{"class":1320},"  console",[807,1807,777],{"class":1327},[807,1809,1810],{"class":1419},"log",[807,1812,1441],{"class":1469},[807,1814,1582],{"class":1327},[807,1816,1817],{"class":1331},"CRM",[807,1819,1582],{"class":1327},[807,1821,1387],{"class":1327},[807,1823,1824],{"class":1320}," phone",[807,1826,1387],{"class":1327},[807,1828,1781],{"class":1320},[807,1830,1387],{"class":1327},[807,1832,1786],{"class":1320},[807,1834,1610],{"class":1469},[807,1836,1837],{"class":809,"line":933},[807,1838,1756],{"class":1327},[807,1840,1841],{"class":809,"line":939},[807,1842,856],{"emptyLinePlaceholder":855},[807,1844,1845,1847,1849,1852,1854,1857,1859],{"class":809,"line":945},[807,1846,1765],{"class":1360},[807,1848,1768],{"class":1360},[807,1850,1851],{"class":1419}," syncCall",[807,1853,1441],{"class":1327},[807,1855,1856],{"class":1444},"event",[807,1858,1458],{"class":1327},[807,1860,1461],{"class":1327},[807,1862,1863,1865,1868,1870,1873,1876,1878,1880,1882,1884,1887,1890,1892,1894,1897,1900,1902],{"class":809,"line":951},[807,1864,1569],{"class":1360},[807,1866,1867],{"class":1320}," response",[807,1869,1396],{"class":1327},[807,1871,1872],{"class":1316}," await",[807,1874,1875],{"class":1419}," fetch",[807,1877,1441],{"class":1469},[807,1879,1623],{"class":1327},[807,1881,292],{"class":1320},[807,1883,1393],{"class":1327},[807,1885,1886],{"class":1331},"\u002Fcalls\u002F",[807,1888,1889],{"class":1327},"${",[807,1891,1856],{"class":1320},[807,1893,777],{"class":1327},[807,1895,1896],{"class":1320},"call_id",[807,1898,1899],{"class":1327},"}`",[807,1901,1387],{"class":1327},[807,1903,1461],{"class":1327},[807,1905,1906,1909,1912,1914,1917,1919,1922,1925,1927,1930,1932],{"class":809,"line":957},[807,1907,1908],{"class":1469},"    headers",[807,1910,1911],{"class":1327},":",[807,1913,1381],{"class":1327},[807,1915,1916],{"class":1469}," Authorization",[807,1918,1911],{"class":1327},[807,1920,1921],{"class":1327}," `",[807,1923,1924],{"class":1331},"Bearer ",[807,1926,1889],{"class":1327},[807,1928,1929],{"class":1320},"DISKA_API_KEY",[807,1931,1899],{"class":1327},[807,1933,1934],{"class":1327}," }\n",[807,1936,1937,1940],{"class":809,"line":962},[807,1938,1939],{"class":1327},"  }",[807,1941,1610],{"class":1469},[807,1943,1944,1946,1948,1950,1953,1955,1958,1960,1963,1965,1968,1970,1972,1975,1977,1979,1981,1984,1986],{"class":809,"line":967},[807,1945,1466],{"class":1316},[807,1947,758],{"class":1469},[807,1949,1472],{"class":1327},[807,1951,1952],{"class":1320},"response",[807,1954,777],{"class":1327},[807,1956,1957],{"class":1320},"ok",[807,1959,1507],{"class":1469},[807,1961,1962],{"class":1316},"throw",[807,1964,1416],{"class":1327},[807,1966,1967],{"class":1419}," Error",[807,1969,1441],{"class":1469},[807,1971,1632],{"class":1327},[807,1973,1974],{"class":1331},"HTTP ",[807,1976,1889],{"class":1327},[807,1978,1952],{"class":1320},[807,1980,777],{"class":1327},[807,1982,1983],{"class":1320},"status",[807,1985,1899],{"class":1327},[807,1987,1610],{"class":1469},[807,1989,1990,1992,1995,1997,1999,2001,2003,2006],{"class":809,"line":973},[807,1991,1569],{"class":1360},[807,1993,1994],{"class":1320}," call",[807,1996,1396],{"class":1327},[807,1998,1872],{"class":1316},[807,2000,1867],{"class":1320},[807,2002,777],{"class":1327},[807,2004,2005],{"class":1419},"json",[807,2007,2008],{"class":1469},"()\n",[807,2010,2011,2014,2016,2018,2020,2022,2025,2027,2029,2031,2034,2036],{"class":809,"line":979},[807,2012,2013],{"class":1316},"  await",[807,2015,1771],{"class":1419},[807,2017,1441],{"class":1469},[807,2019,1856],{"class":1320},[807,2021,777],{"class":1327},[807,2023,2024],{"class":1320},"caller_contact",[807,2026,1387],{"class":1327},[807,2028,1994],{"class":1320},[807,2030,777],{"class":1327},[807,2032,2033],{"class":1320},"caller_name",[807,2035,1387],{"class":1327},[807,2037,1461],{"class":1327},[807,2039,2040,2043,2045,2047,2049,2052],{"class":809,"line":985},[807,2041,2042],{"class":1469},"    diska_call_id",[807,2044,1911],{"class":1327},[807,2046,1994],{"class":1320},[807,2048,777],{"class":1327},[807,2050,2051],{"class":1320},"id",[807,2053,2054],{"class":1327},",\n",[807,2056,2057,2060,2062,2064,2066,2069],{"class":809,"line":991},[807,2058,2059],{"class":1469},"    started_at",[807,2061,1911],{"class":1327},[807,2063,1994],{"class":1320},[807,2065,777],{"class":1327},[807,2067,2068],{"class":1320},"started_at",[807,2070,2054],{"class":1327},[807,2072,2073,2076,2078,2080,2082,2085],{"class":809,"line":997},[807,2074,2075],{"class":1469},"    duration_seconds",[807,2077,1911],{"class":1327},[807,2079,1994],{"class":1320},[807,2081,777],{"class":1327},[807,2083,2084],{"class":1320},"duration_seconds",[807,2086,2054],{"class":1327},[807,2088,2089,2092,2094,2096,2098,2101],{"class":809,"line":1003},[807,2090,2091],{"class":1469},"    agent",[807,2093,1911],{"class":1327},[807,2095,1994],{"class":1320},[807,2097,777],{"class":1327},[807,2099,2100],{"class":1320},"agent_name",[807,2102,2054],{"class":1327},[807,2104,2105,2108,2110,2112,2114,2117],{"class":809,"line":1009},[807,2106,2107],{"class":1469},"    summary",[807,2109,1911],{"class":1327},[807,2111,1994],{"class":1320},[807,2113,777],{"class":1327},[807,2115,2116],{"class":1320},"summary",[807,2118,2054],{"class":1327},[807,2120,2121,2124,2126,2129,2131,2134],{"class":809,"line":1015},[807,2122,2123],{"class":1469},"    sentiment",[807,2125,1911],{"class":1327},[807,2127,2128],{"class":1320}," event",[807,2130,777],{"class":1327},[807,2132,2133],{"class":1320},"sentiment",[807,2135,2054],{"class":1327},[807,2137,2138,2141,2143,2145,2147,2150,2153],{"class":809,"line":1021},[807,2139,2140],{"class":1469},"    data",[807,2142,1911],{"class":1327},[807,2144,2128],{"class":1320},[807,2146,777],{"class":1327},[807,2148,2149],{"class":1320},"extracted_data",[807,2151,2152],{"class":1327}," ??",[807,2154,2155],{"class":1327}," {}\n",[807,2157,2158,2160],{"class":809,"line":1027},[807,2159,1939],{"class":1327},[807,2161,1610],{"class":1469},[807,2163,2164],{"class":809,"line":1033},[807,2165,1756],{"class":1327},[807,2167,2168],{"class":809,"line":1039},[807,2169,856],{"emptyLinePlaceholder":855},[807,2171,2172,2175,2177,2180,2182,2184,2187,2189,2192,2194,2197],{"class":809,"line":1045},[807,2173,2174],{"class":1320},"http",[807,2176,777],{"class":1327},[807,2178,2179],{"class":1419},"createServer",[807,2181,1441],{"class":1320},[807,2183,1441],{"class":1327},[807,2185,2186],{"class":1444},"req",[807,2188,1387],{"class":1327},[807,2190,2191],{"class":1444}," res",[807,2193,1458],{"class":1327},[807,2195,2196],{"class":1360}," =>",[807,2198,1461],{"class":1327},[807,2200,2201,2203,2205,2207,2209,2212,2215,2217,2220,2222,2224,2227,2229,2232,2234,2236,2239,2241,2243,2245,2247,2249,2252,2254,2257,2259,2261,2264],{"class":809,"line":1051},[807,2202,1466],{"class":1316},[807,2204,758],{"class":1469},[807,2206,2186],{"class":1320},[807,2208,777],{"class":1327},[807,2210,2211],{"class":1320},"method",[807,2213,2214],{"class":1327}," !==",[807,2216,1328],{"class":1327},[807,2218,2219],{"class":1331},"POST",[807,2221,1582],{"class":1327},[807,2223,1501],{"class":1327},[807,2225,2226],{"class":1320}," req",[807,2228,777],{"class":1327},[807,2230,2231],{"class":1320},"url",[807,2233,2214],{"class":1327},[807,2235,1328],{"class":1327},[807,2237,2238],{"class":1331},"\u002Fhooks\u002Fdiska",[807,2240,1582],{"class":1327},[807,2242,1507],{"class":1469},[807,2244,1560],{"class":1316},[807,2246,2191],{"class":1320},[807,2248,777],{"class":1327},[807,2250,2251],{"class":1419},"writeHead",[807,2253,1441],{"class":1469},[807,2255,2256],{"class":1535},"404",[807,2258,1458],{"class":1469},[807,2260,777],{"class":1327},[807,2262,2263],{"class":1419},"end",[807,2265,2008],{"class":1469},[807,2267,2268,2270,2273,2275],{"class":809,"line":1056},[807,2269,1569],{"class":1360},[807,2271,2272],{"class":1320}," chunks",[807,2274,1396],{"class":1327},[807,2276,2277],{"class":1469}," []\n",[807,2279,2280,2283,2285,2288,2290,2292,2295,2297,2299,2302,2304,2306,2308,2311,2313,2316],{"class":809,"line":1061},[807,2281,2282],{"class":1320},"  req",[807,2284,777],{"class":1327},[807,2286,2287],{"class":1419},"on",[807,2289,1441],{"class":1469},[807,2291,1582],{"class":1327},[807,2293,2294],{"class":1331},"data",[807,2296,1582],{"class":1327},[807,2298,1387],{"class":1327},[807,2300,2301],{"class":1444}," chunk",[807,2303,2196],{"class":1360},[807,2305,2272],{"class":1320},[807,2307,777],{"class":1327},[807,2309,2310],{"class":1419},"push",[807,2312,1441],{"class":1469},[807,2314,2315],{"class":1320},"chunk",[807,2317,2318],{"class":1469},"))\n",[807,2320,2321,2323,2325,2327,2329,2331,2333,2335,2337,2340,2342],{"class":809,"line":1067},[807,2322,2282],{"class":1320},[807,2324,777],{"class":1327},[807,2326,2287],{"class":1419},[807,2328,1441],{"class":1469},[807,2330,1582],{"class":1327},[807,2332,2263],{"class":1331},[807,2334,1582],{"class":1327},[807,2336,1387],{"class":1327},[807,2338,2339],{"class":1327}," ()",[807,2341,2196],{"class":1360},[807,2343,1461],{"class":1327},[807,2345,2346,2349,2351,2353,2355,2357,2360,2362,2365,2367],{"class":809,"line":1073},[807,2347,2348],{"class":1360},"    const",[807,2350,1450],{"class":1320},[807,2352,1396],{"class":1327},[807,2354,1673],{"class":1320},[807,2356,777],{"class":1327},[807,2358,2359],{"class":1419},"concat",[807,2361,1441],{"class":1469},[807,2363,2364],{"class":1320},"chunks",[807,2366,1507],{"class":1469},[807,2368,2369],{"class":1310},"\u002F\u002F o corpo bruto, antes de interpretar o JSON\n",[807,2371,2372,2375,2377,2379,2382,2384,2386,2388,2391,2394,2396,2399,2401,2404,2406,2408,2410,2412,2414,2416,2418,2420,2423,2425,2428,2430,2432,2434,2436,2438,2441,2443,2445,2447],{"class":809,"line":1079},[807,2373,2374],{"class":1316},"    if",[807,2376,758],{"class":1469},[807,2378,1472],{"class":1327},[807,2380,2381],{"class":1419},"isValid",[807,2383,1441],{"class":1469},[807,2385,2186],{"class":1320},[807,2387,777],{"class":1327},[807,2389,2390],{"class":1320},"headers",[807,2392,2393],{"class":1469},"[",[807,2395,1582],{"class":1327},[807,2397,2398],{"class":1331},"x-diska-timestamp",[807,2400,1582],{"class":1327},[807,2402,2403],{"class":1469},"]",[807,2405,1387],{"class":1327},[807,2407,1450],{"class":1320},[807,2409,1387],{"class":1327},[807,2411,2226],{"class":1320},[807,2413,777],{"class":1327},[807,2415,2390],{"class":1320},[807,2417,2393],{"class":1469},[807,2419,1582],{"class":1327},[807,2421,2422],{"class":1331},"x-diska-signature",[807,2424,1582],{"class":1327},[807,2426,2427],{"class":1469},"])) ",[807,2429,1560],{"class":1316},[807,2431,2191],{"class":1320},[807,2433,777],{"class":1327},[807,2435,2251],{"class":1419},[807,2437,1441],{"class":1469},[807,2439,2440],{"class":1535},"401",[807,2442,1458],{"class":1469},[807,2444,777],{"class":1327},[807,2446,2263],{"class":1419},[807,2448,2008],{"class":1469},[807,2450,2451,2454,2456,2458,2460,2463,2465,2467,2469,2471],{"class":809,"line":1085},[807,2452,2453],{"class":1320},"    res",[807,2455,777],{"class":1327},[807,2457,2251],{"class":1419},[807,2459,1441],{"class":1469},[807,2461,2462],{"class":1535},"200",[807,2464,1458],{"class":1469},[807,2466,777],{"class":1327},[807,2468,2263],{"class":1419},[807,2470,1423],{"class":1469},[807,2472,2473],{"class":1310},"\u002F\u002F responda já; processe a seguir\n",[807,2475,2476,2478,2481,2483,2485,2487,2489,2491,2493,2496,2498],{"class":809,"line":1090},[807,2477,2348],{"class":1360},[807,2479,2480],{"class":1320}," delivery",[807,2482,1396],{"class":1327},[807,2484,2226],{"class":1320},[807,2486,777],{"class":1327},[807,2488,2390],{"class":1320},[807,2490,2393],{"class":1469},[807,2492,1582],{"class":1327},[807,2494,2495],{"class":1331},"x-diska-delivery",[807,2497,1582],{"class":1327},[807,2499,2500],{"class":1469},"]\n",[807,2502,2503,2505,2507,2510,2512,2515,2517,2520,2522,2524],{"class":809,"line":1095},[807,2504,2374],{"class":1316},[807,2506,758],{"class":1469},[807,2508,2509],{"class":1320},"seen",[807,2511,777],{"class":1327},[807,2513,2514],{"class":1419},"has",[807,2516,1441],{"class":1469},[807,2518,2519],{"class":1320},"delivery",[807,2521,1549],{"class":1469},[807,2523,1560],{"class":1316},[807,2525,2526],{"class":1310}," \u002F\u002F repetição de uma entrega que já recebeu\n",[807,2528,2529,2532,2534,2537,2539,2541],{"class":809,"line":1101},[807,2530,2531],{"class":1320},"    seen",[807,2533,777],{"class":1327},[807,2535,2536],{"class":1419},"add",[807,2538,1441],{"class":1469},[807,2540,2519],{"class":1320},[807,2542,1610],{"class":1469},[807,2544,2545,2547,2549,2551,2554,2556,2559,2561,2563],{"class":809,"line":1107},[807,2546,2348],{"class":1360},[807,2548,2128],{"class":1320},[807,2550,1396],{"class":1327},[807,2552,2553],{"class":1320}," JSON",[807,2555,777],{"class":1327},[807,2557,2558],{"class":1419},"parse",[807,2560,1441],{"class":1469},[807,2562,1643],{"class":1320},[807,2564,1610],{"class":1469},[807,2566,2567,2569,2571,2573,2575,2577,2579,2581,2584,2586,2588],{"class":809,"line":1113},[807,2568,2374],{"class":1316},[807,2570,758],{"class":1469},[807,2572,1856],{"class":1320},[807,2574,777],{"class":1327},[807,2576,1856],{"class":1320},[807,2578,1725],{"class":1327},[807,2580,1328],{"class":1327},[807,2582,2583],{"class":1331},"call.completed",[807,2585,1582],{"class":1327},[807,2587,1507],{"class":1469},[807,2589,2590],{"class":1327},"{\n",[807,2592,2593,2596,2598,2600,2602,2604,2607,2609,2612,2614,2617,2619,2622,2624,2626,2629,2631,2633,2635,2637,2639,2641,2644,2646],{"class":809,"line":1119},[807,2594,2595],{"class":1419},"      syncCall",[807,2597,1441],{"class":1469},[807,2599,1856],{"class":1320},[807,2601,1458],{"class":1469},[807,2603,777],{"class":1327},[807,2605,2606],{"class":1419},"catch",[807,2608,1441],{"class":1469},[807,2610,2611],{"class":1444},"err",[807,2613,2196],{"class":1360},[807,2615,2616],{"class":1320}," console",[807,2618,777],{"class":1327},[807,2620,2621],{"class":1419},"error",[807,2623,1441],{"class":1469},[807,2625,1582],{"class":1327},[807,2627,2628],{"class":1331},"sincronização falhou",[807,2630,1582],{"class":1327},[807,2632,1387],{"class":1327},[807,2634,2128],{"class":1320},[807,2636,777],{"class":1327},[807,2638,1896],{"class":1320},[807,2640,1387],{"class":1327},[807,2642,2643],{"class":1320}," err",[807,2645,1549],{"class":1469},[807,2647,2648],{"class":1310},"\u002F\u002F a reconciliação apanha o que falhar\n",[807,2650,2651],{"class":809,"line":1125},[807,2652,2653],{"class":1327},"    }\n",[807,2655,2656,2658],{"class":809,"line":1131},[807,2657,1939],{"class":1327},[807,2659,1610],{"class":1469},[807,2661,2662,2664,2666,2668,2671,2673,2676,2679,2681,2684,2686,2689,2691,2694],{"class":809,"line":1137},[807,2663,1393],{"class":1327},[807,2665,1458],{"class":1320},[807,2667,777],{"class":1327},[807,2669,2670],{"class":1419},"listen",[807,2672,1441],{"class":1320},[807,2674,2675],{"class":1419},"Number",[807,2677,2678],{"class":1320},"(process",[807,2680,777],{"class":1327},[807,2682,2683],{"class":1320},"env",[807,2685,777],{"class":1327},[807,2687,2688],{"class":1320},"PORT ",[807,2690,1510],{"class":1327},[807,2692,2693],{"class":1535}," 3000",[807,2695,2318],{"class":1320},[712,2697,2698],{},"O que o receptor faz, por ordem:",[745,2700,2701,2714,2723,2732,2744],{},[724,2702,2703,2706,2707,2709,2710,777],{},[755,2704,2705],{},"Verifica a assinatura"," sobre o corpo bruto, com o secret do endpoint. Um pedido sem assinatura válida recebe ",[760,2708,2440],{},". Veja ",[716,2711,2713],{"href":2712},"\u002Fpt\u002Fapi\u002Fwebhooks#verificar-a-assinatura","Verificar a assinatura",[724,2715,2716,2719,2720,777],{},[755,2717,2718],{},"Ignora repetições."," Uma entrega repetida traz o mesmo ",[760,2721,2722],{},"X-Diska-Delivery",[724,2724,2725,2728,2729,2731],{},[755,2726,2727],{},"Responde logo"," com ",[760,2730,2462],{},", e processa a seguir: a Diska espera no máximo 10 segundos.",[724,2733,2734,2737,2738,2743],{},[755,2735,2736],{},"Lê o detalhe da chamada"," em ",[716,2739,2740],{"href":374},[760,2741,2742],{},"GET \u002Fv1\u002Fcalls\u002F{call_id}",", para ter o resumo, a duração e o nome de quem ligou. O evento já traz o sentimento e os dados extraídos.",[724,2745,2746,2737,2749,2752,2753,2756,2757,2760,2761,2764],{},[755,2747,2748],{},"Chama o CRM",[760,2750,2751],{},"crm_upsert"," \u002F ",[760,2754,2755],{},"crmUpsert",". Substitua o ",[760,2758,2759],{},"print"," pela API do seu CRM, e use o ",[760,2762,2763],{},"diska_call_id"," como chave única da actividade, para nunca a criar duas vezes.",[712,2766,2767,2768,2771,2772,2774],{},"O evento de teste (",[760,2769,2770],{},"ping",") também recebe ",[760,2773,2462],{},", para o passo 3 funcionar.",[712,2776,2777,2778,784,2780,2783],{},"Para correr o receptor, com as variáveis ",[760,2779,1929],{},[760,2781,2782],{},"DISKA_WEBHOOK_SECRET"," definidas:",[797,2785,2789],{"className":2786,"code":2787,"language":2788,"meta":803,"style":803},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","pip install flask requests\nflask --app receiver run --port 3000   # Python\nnode receiver.mjs                      # Node.js (porta 3000)\n","bash",[760,2790,2791,2806,2827],{"__ignoreMap":803},[807,2792,2793,2797,2800,2803],{"class":809,"line":810},[807,2794,2796],{"class":2795},"sBMFI","pip",[807,2798,2799],{"class":1331}," install",[807,2801,2802],{"class":1331}," flask",[807,2804,2805],{"class":1331}," requests\n",[807,2807,2808,2810,2813,2816,2819,2822,2824],{"class":809,"line":816},[807,2809,783],{"class":2795},[807,2811,2812],{"class":1331}," --app",[807,2814,2815],{"class":1331}," receiver",[807,2817,2818],{"class":1331}," run",[807,2820,2821],{"class":1331}," --port",[807,2823,2693],{"class":1535},[807,2825,2826],{"class":1310},"   # Python\n",[807,2828,2829,2832,2835],{"class":809,"line":822},[807,2830,2831],{"class":2795},"node",[807,2833,2834],{"class":1331}," receiver.mjs",[807,2836,2837],{"class":1310},"                      # Node.js (porta 3000)\n",[712,2839,2840],{},"Em produção, ponha-o atrás do seu servidor web ou do seu proxy, com HTTPS.",[740,2842,2844],{"id":2843},"_2-registe-o-endpoint","2. Registe o endpoint",[797,2846,2848],{"className":2786,"code":2847,"language":2788,"meta":803,"style":803},"curl -X POST https:\u002F\u002Fapi.diska.ai\u002Fv1\u002Fwebhook-endpoints \\\n  -H \"Authorization: Bearer $DISKA_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"url\": \"https:\u002F\u002Fo-seu-sistema.com\u002Fhooks\u002Fdiska\", \"description\": \"CRM\", \"events\": [\"call.completed\"]}'\n",[760,2849,2850,2867,2886,2899],{"__ignoreMap":803},[807,2851,2852,2855,2858,2861,2864],{"class":809,"line":810},[807,2853,2854],{"class":2795},"curl",[807,2856,2857],{"class":1331}," -X",[807,2859,2860],{"class":1331}," POST",[807,2862,2863],{"class":1331}," https:\u002F\u002Fapi.diska.ai\u002Fv1\u002Fwebhook-endpoints",[807,2865,2866],{"class":1320}," \\\n",[807,2868,2869,2872,2875,2878,2881,2884],{"class":809,"line":816},[807,2870,2871],{"class":1331},"  -H",[807,2873,2874],{"class":1327}," \"",[807,2876,2877],{"class":1331},"Authorization: Bearer ",[807,2879,2880],{"class":1320},"$DISKA_API_KEY",[807,2882,2883],{"class":1327},"\"",[807,2885,2866],{"class":1320},[807,2887,2888,2890,2892,2895,2897],{"class":809,"line":822},[807,2889,2871],{"class":1331},[807,2891,2874],{"class":1327},[807,2893,2894],{"class":1331},"Content-Type: application\u002Fjson",[807,2896,2883],{"class":1327},[807,2898,2866],{"class":1320},[807,2900,2901,2904,2906,2909],{"class":809,"line":828},[807,2902,2903],{"class":1331},"  -d",[807,2905,1328],{"class":1327},[807,2907,2908],{"class":1331},"{\"url\": \"https:\u002F\u002Fo-seu-sistema.com\u002Fhooks\u002Fdiska\", \"description\": \"CRM\", \"events\": [\"call.completed\"]}",[807,2910,1335],{"class":1327},[712,2912,2913,2914,758,2917,1507,2920,2923,2924,2926,2927,777],{},"A resposta traz o ",[760,2915,2916],{},"secret",[760,2918,2919],{},"dskw_…",[755,2921,2922],{},"só desta vez",". Guarde-o em ",[760,2925,2782],{}," e reinicie o receptor. Guarde também o ",[760,2928,2929],{},"endpoint.id",[740,2931,2933],{"id":2932},"_3-teste","3. Teste",[797,2935,2937],{"className":2786,"code":2936,"language":2788,"meta":803,"style":803},"curl -X POST https:\u002F\u002Fapi.diska.ai\u002Fv1\u002Fwebhook-endpoints\u002F\u003Cendpoint_id>\u002Ftest \\\n  -H \"Authorization: Bearer $DISKA_API_KEY\"\n",[760,2938,2939,2966],{"__ignoreMap":803},[807,2940,2941,2943,2945,2947,2950,2953,2956,2959,2961,2964],{"class":809,"line":810},[807,2942,2854],{"class":2795},[807,2944,2857],{"class":1331},[807,2946,2860],{"class":1331},[807,2948,2949],{"class":1331}," https:\u002F\u002Fapi.diska.ai\u002Fv1\u002Fwebhook-endpoints\u002F",[807,2951,2952],{"class":1327},"\u003C",[807,2954,2955],{"class":1331},"endpoint_i",[807,2957,2958],{"class":1320},"d",[807,2960,1552],{"class":1327},[807,2962,2963],{"class":1331},"\u002Ftest",[807,2965,2866],{"class":1320},[807,2967,2968,2970,2972,2974,2976],{"class":809,"line":816},[807,2969,2871],{"class":1331},[807,2971,2874],{"class":1327},[807,2973,2877],{"class":1331},[807,2975,2880],{"class":1320},[807,2977,2978],{"class":1327},"\"\n",[712,2980,2981,2982,2985,2986,2989,2990,2992,2993,2995],{},"A resposta deve trazer ",[760,2983,2984],{},"\"status\": \"delivered\"",". Se trouxer ",[760,2987,2988],{},"failed",", o campo ",[760,2991,2621],{}," diz porquê: URL inacessível, certificado inválido, ou o receptor respondeu ",[760,2994,2440],{}," porque o secret não é o certo.",[712,2997,2998,2999,3001],{},"Depois, ligue para o número do agente e termine a chamada normalmente. Quando o processamento pós-chamada acabar, o receptor recebe ",[760,3000,2583],{}," e o contacto aparece no CRM.",[740,3003,3005],{"id":3004},"_4-reconcilie-uma-vez-por-dia","4. Reconcilie uma vez por dia",[712,3007,3008,3009,3014],{},"As entregas são feitas no melhor esforço: se o seu servidor estiver em baixo durante as repetições, o evento perde-se. A fonte de verdade é ",[716,3010,3011],{"href":370},[760,3012,3013],{},"GET \u002Fv1\u002Fcalls",". Este script percorre as chamadas concluídas dos últimos dias:",[794,3016,3017],{},[797,3018,3020],{"className":799,"code":3019,"filename":801,"language":802,"meta":803,"style":803},"import os\nimport time\nfrom datetime import datetime, timedelta, timezone\n\nimport requests\n\nAPI = \"https:\u002F\u002Fapi.diska.ai\u002Fv1\"\nsession = requests.Session()\nsession.headers[\"Authorization\"] = f\"Bearer {os.environ['DISKA_API_KEY']}\"\n\n\ndef get(path: str, params: dict | None = None) -> dict:\n    while True:\n        response = session.get(f\"{API}{path}\", params=params, timeout=60)\n        if response.status_code == 429:  # limite de pedidos: espere o que a API indica\n            time.sleep(int(response.headers.get(\"Retry-After\", \"5\")))\n            continue\n        response.raise_for_status()\n        return response.json()\n\n\ndef calls_since(since: datetime):\n    \"\"\"Chamadas concluídas desde `since`, da mais recente para a mais antiga.\"\"\"\n    params = {\"cursor\": \"start\", \"limit\": 200, \"status\": \"completed\"}\n    while True:\n        page = get(\"\u002Fcalls\", params)\n        for call in page[\"items\"]:\n            if call[\"started_at\"] and datetime.fromisoformat(call[\"started_at\"]) \u003C since:\n                return  # a lista vem da mais recente para a mais antiga: pode parar\n            yield call\n        if not page[\"next_cursor\"]:\n            return\n        params[\"cursor\"] = page[\"next_cursor\"]\n\n\nsince = datetime.now(timezone.utc) - timedelta(days=2)  # um pouco mais do que o intervalo entre execuções\nfor call in calls_since(since):\n    print(\"verificar no CRM:\", call[\"id\"], call[\"started_at\"])  # crie a actividade se ainda não existir\n",[760,3021,3022,3026,3030,3035,3039,3043,3047,3051,3056,3061,3065,3069,3074,3078,3083,3088,3093,3098,3103,3108,3112,3116,3121,3126,3131,3135,3140,3145,3150,3155,3160,3165,3170,3175,3179,3183,3188,3193],{"__ignoreMap":803},[807,3023,3024],{"class":809,"line":810},[807,3025,831],{},[807,3027,3028],{"class":809,"line":816},[807,3029,849],{},[807,3031,3032],{"class":809,"line":822},[807,3033,3034],{},"from datetime import datetime, timedelta, timezone\n",[807,3036,3037],{"class":809,"line":828},[807,3038,856],{"emptyLinePlaceholder":855},[807,3040,3041],{"class":809,"line":834},[807,3042,862],{},[807,3044,3045],{"class":809,"line":840},[807,3046,856],{"emptyLinePlaceholder":855},[807,3048,3049],{"class":809,"line":846},[807,3050,879],{},[807,3052,3053],{"class":809,"line":852},[807,3054,3055],{},"session = requests.Session()\n",[807,3057,3058],{"class":809,"line":859},[807,3059,3060],{},"session.headers[\"Authorization\"] = f\"Bearer {os.environ['DISKA_API_KEY']}\"\n",[807,3062,3063],{"class":809,"line":865},[807,3064,856],{"emptyLinePlaceholder":855},[807,3066,3067],{"class":809,"line":871},[807,3068,856],{"emptyLinePlaceholder":855},[807,3070,3071],{"class":809,"line":876},[807,3072,3073],{},"def get(path: str, params: dict | None = None) -> dict:\n",[807,3075,3076],{"class":809,"line":882},[807,3077,1239],{},[807,3079,3080],{"class":809,"line":888},[807,3081,3082],{},"        response = session.get(f\"{API}{path}\", params=params, timeout=60)\n",[807,3084,3085],{"class":809,"line":894},[807,3086,3087],{},"        if response.status_code == 429:  # limite de pedidos: espere o que a API indica\n",[807,3089,3090],{"class":809,"line":899},[807,3091,3092],{},"            time.sleep(int(response.headers.get(\"Retry-After\", \"5\")))\n",[807,3094,3095],{"class":809,"line":905},[807,3096,3097],{},"            continue\n",[807,3099,3100],{"class":809,"line":911},[807,3101,3102],{},"        response.raise_for_status()\n",[807,3104,3105],{"class":809,"line":917},[807,3106,3107],{},"        return response.json()\n",[807,3109,3110],{"class":809,"line":922},[807,3111,856],{"emptyLinePlaceholder":855},[807,3113,3114],{"class":809,"line":927},[807,3115,856],{"emptyLinePlaceholder":855},[807,3117,3118],{"class":809,"line":933},[807,3119,3120],{},"def calls_since(since: datetime):\n",[807,3122,3123],{"class":809,"line":939},[807,3124,3125],{},"    \"\"\"Chamadas concluídas desde `since`, da mais recente para a mais antiga.\"\"\"\n",[807,3127,3128],{"class":809,"line":945},[807,3129,3130],{},"    params = {\"cursor\": \"start\", \"limit\": 200, \"status\": \"completed\"}\n",[807,3132,3133],{"class":809,"line":951},[807,3134,1239],{},[807,3136,3137],{"class":809,"line":957},[807,3138,3139],{},"        page = get(\"\u002Fcalls\", params)\n",[807,3141,3142],{"class":809,"line":962},[807,3143,3144],{},"        for call in page[\"items\"]:\n",[807,3146,3147],{"class":809,"line":967},[807,3148,3149],{},"            if call[\"started_at\"] and datetime.fromisoformat(call[\"started_at\"]) \u003C since:\n",[807,3151,3152],{"class":809,"line":973},[807,3153,3154],{},"                return  # a lista vem da mais recente para a mais antiga: pode parar\n",[807,3156,3157],{"class":809,"line":979},[807,3158,3159],{},"            yield call\n",[807,3161,3162],{"class":809,"line":985},[807,3163,3164],{},"        if not page[\"next_cursor\"]:\n",[807,3166,3167],{"class":809,"line":991},[807,3168,3169],{},"            return\n",[807,3171,3172],{"class":809,"line":997},[807,3173,3174],{},"        params[\"cursor\"] = page[\"next_cursor\"]\n",[807,3176,3177],{"class":809,"line":1003},[807,3178,856],{"emptyLinePlaceholder":855},[807,3180,3181],{"class":809,"line":1009},[807,3182,856],{"emptyLinePlaceholder":855},[807,3184,3185],{"class":809,"line":1015},[807,3186,3187],{},"since = datetime.now(timezone.utc) - timedelta(days=2)  # um pouco mais do que o intervalo entre execuções\n",[807,3189,3190],{"class":809,"line":1021},[807,3191,3192],{},"for call in calls_since(since):\n",[807,3194,3195],{"class":809,"line":1027},[807,3196,3197],{},"    print(\"verificar no CRM:\", call[\"id\"], call[\"started_at\"])  # crie a actividade se ainda não existir\n",[712,3199,3200,3201,3204],{},"Corra-o uma vez por dia, por exemplo com ",[760,3202,3203],{},"cron",", e crie no CRM a actividade das chamadas que lá não estejam. Como a lista vem da mais recente para a mais antiga, o script pára na primeira chamada anterior à data de corte.",[740,3206,3208],{"id":3207},"para-produção","Para produção",[745,3210,3211,3217,3220,3223],{},[724,3212,3213,3214,3216],{},"Guarde os ",[760,3215,2722],{}," processados numa tabela, não em memória: o receptor pode reiniciar.",[724,3218,3219],{},"Use uma fila persistente (por exemplo Redis ou SQS) em vez da fila em memória.",[724,3221,3222],{},"Registe as falhas de sincronização: a reconciliação recupera-as, mas convém saber que aconteceram.",[724,3224,3225,3226,3231,3232,784,3235,3238,3239,777],{},"Vigie o endpoint: ",[716,3227,3228],{"href":518},[760,3229,3230],{},"GET \u002Fv1\u002Fwebhook-endpoints"," mostra ",[760,3233,3234],{},"failure_count",[760,3236,3237],{},"active",". Ao fim de 20 falhas seguidas o endpoint é desactivado; depois de corrigir, reactive-o com ",[760,3240,3241],{},"{\"active\": true}",[3243,3244,3245],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}",{"title":803,"searchDepth":816,"depth":816,"links":3247},[3248,3249,3250,3251,3252,3253],{"id":742,"depth":816,"text":743},{"id":791,"depth":816,"text":792},{"id":2843,"depth":816,"text":2844},{"id":2932,"depth":816,"text":2933},{"id":3004,"depth":816,"text":3005},{"id":3207,"depth":816,"text":3208},"Cada chamada concluída chega ao seu servidor por webhook e cria ou actualiza o contacto e a actividade no CRM.","md",null,{},{"title":543,"description":3254},"ZDngFf2OviWuAcB__YJqYb0WRIpDZjYpjN5u-CDmtqk",[3261,3263],{"title":537,"path":538,"stem":539,"description":3262,"children":-1},"Integrações completas com a API da DISKA, passo a passo, com código testado em Python e JavaScript.",{"title":547,"path":548,"stem":549,"description":3264,"children":-1},"Todo o histórico para CSV, ou com as transcrições para JSONL, com paginação por cursor.",1795253824227]