"use strict";(self.webpackChunknewoaks_help=self.webpackChunknewoaks_help||[]).push([[8389],{6075:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>d,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>h});const i=JSON.parse('{"id":"webhook/lead","title":"Leads Webhook","description":"The webhook will process data per chatbot. Webhook will post leads and appointment records to your CRM in JSON format daily.","source":"@site/developer/webhook/002.lead.md","sourceDirName":"webhook","slug":"/webhook/lead","permalink":"/guides/developer/webhook/lead","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"sidebar_position":2},"sidebar":"sidebar","previous":{"title":"Triggering IPs","permalink":"/guides/developer/webhook/trigger-ip"},"next":{"title":"Conversation Webhooks","permalink":"/guides/developer/webhook/conversation"}}');var o=t(4848),r=t(8453),s=(t(9357),t(8175));const a={sidebar_position:2},d="Leads Webhook",c={},h=[{value:"Setting up a Webhook",id:"setting-up-a-webhook",level:2},{value:"Receiving Endpoint",id:"receiving-endpoint",level:2},{value:"X-Webhook-Signature",id:"x-webhook-signature",level:2},{value:"Listening for Leads and Appointments Events",id:"listening-for-leads-and-appointments-events",level:2},{value:"Error retry",id:"error-retry",level:2}];function l(e){const n={code:"code",h1:"h1",h2:"h2",header:"header",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.header,{children:(0,o.jsx)(n.h1,{id:"leads-webhook",children:"Leads Webhook"})}),"\n",(0,o.jsx)(n.p,{children:"The webhook will process data per chatbot. Webhook will post leads and appointment records to your CRM in JSON format daily."}),"\n",(0,o.jsx)(n.h2,{id:"setting-up-a-webhook",children:"Setting up a Webhook"}),"\n",(0,o.jsxs)(n.p,{children:["To set up a Webhook you must have been issued with a ",(0,o.jsx)(s.A,{})," logon (contact ",(0,o.jsx)(s.A,{})," Support if you do not already have this access):"]}),"\n",(0,o.jsxs)(n.ol,{children:["\n",(0,o.jsxs)(n.li,{children:["Log on to ",(0,o.jsx)(s.A,{})," and click workspace."]}),"\n",(0,o.jsx)(n.li,{children:"Input the webhook URL of the Endpoint you configured in the Webhook tab."}),"\n",(0,o.jsx)(n.li,{children:"click save."}),"\n"]}),"\n",(0,o.jsx)(n.p,{children:"Once the webhook URL is entered, the webhook Sign Key is automatically generated."}),"\n",(0,o.jsx)(n.h2,{id:"receiving-endpoint",children:"Receiving Endpoint"}),"\n",(0,o.jsxs)(n.p,{children:["Gain confidence in the authenticity of your webhooks when you use a webhook signing key that mentioned above, a unique secret key shared between your application and ",(0,o.jsx)(s.A,{}),", to verify the events sent to your endpoints. The webhook signing key will produce the",(0,o.jsx)(n.code,{children:"X-Webhook-Signature"}),", which you can use to compare against an expected webhook signature, to verify events from ",(0,o.jsx)(s.A,{}),"."]}),"\n",(0,o.jsx)(n.h2,{id:"x-webhook-signature",children:"X-Webhook-Signature"}),"\n",(0,o.jsxs)(n.p,{children:["When ",(0,o.jsx)(s.A,{})," sends your app a webhook, it will include the",(0,o.jsx)(n.code,{children:"X-Webhook-Signature"})," header in the following format:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:"X-Webhook-Signature: t=1492774577,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Compare the ",(0,o.jsx)(n.code,{children:"X-Webhook-Signature"}),", prefixed by ",(0,o.jsx)(n.code,{children:"v1="}),", to the expected signature. If they match, then you can trust that the event payload was issued by ",(0,o.jsx)(s.A,{})," and has not been tampered with."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-JavaScript",children:"const crypto = require('crypto');\n\n// Your application's webhook signing key\nconst webhookSigningKey = ({}).WEBHOOK_SIGNING_KEY;\n\n// Extract the timestamp and signature from the header\nconst newoaksSignature = req.get('X-Webhook-Signature');\nconst { t, signature } = newoaksSignature.split(',').reduce((acc, currentValue) => {\n    const [key, value] = currentValue.split('=');\n\n    if (key === 't') {\n    // UNIX timestamp\n    acc.t = value;\n    }\n\n    if (key === 'v1') {\n    acc.signature = value\n    }\n    \n    return acc;\n}, {\n    t: '',\n    signature: ''\n});\n\nif (!t || !signature) throw new Error('Invalid Signature');\n\n// Create the signed payload by concatenating the timestamp (t), the character '.' and the request body's JSON payload.\nconst data = t + '.' + JSON.stringify(req.body);\n\nconst expectedSignature = crypto.createHmac('sha256', webhookSigningKey).update(data, 'utf8').digest('hex');\n\n// Determine the expected signature by computing an HMAC with the SHA256 hash function.\n\nif (expectedSignature !== signature) {\n    // Signature is invalid!\n    throw new Error('Invalid Signature');\n}\n"})}),"\n",(0,o.jsx)(n.h2,{id:"listening-for-leads-and-appointments-events",children:"Listening for Leads and Appointments Events"}),"\n",(0,o.jsx)(n.p,{children:"When an event occurs, it is notified to your configured webhook URL. Push any new leads and appointments immediately,"}),"\n",(0,o.jsx)(n.p,{children:"Notification Details - HTTP POST Request"}),"\n",(0,o.jsxs)(n.table,{children:[(0,o.jsx)(n.thead,{children:(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.th,{children:"Method"}),(0,o.jsx)(n.th,{children:"POST"})]})}),(0,o.jsx)(n.tbody,{children:(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{children:"Content-Type"}),(0,o.jsx)(n.td,{children:"application/json"})]})})]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.strong,{children:"JSON Body"})}),"\n",(0,o.jsx)(n.p,{children:"Example:"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-JSON",children:'{\n    // SerialNumber string Chatbot ID\n    "SerialNumber": "59001dd73709417321c58b11693183a2",\n    // Type string There are two types: Lead and Appointment\n    "Type": "Lead",\n    // FirstName string User First Name\n    "FirstName": "David",\n    // LastName string User Last Name\n    "LastName": "Garcia",\n    // Email string User\'s Email\n    "Email": "test@qq.com",\n    // PhoneNumber string User\'s phone number\n    "PhoneNumber": "",\n    // CreateTime string Creation time (UTC time)\n    "CreateTime": "2023-11-23T18:36:21.512302Z",\n    // Content string Remarks or appointment content\n    "Content": "test",\n    // SessionID int Session ID\n    "SessionID": 31305,\n    // URI string Source uri\n    "URI": "www.google.com"\n}\n'})}),"\n",(0,o.jsx)(n.p,{children:"JSON Body Description:"}),"\n",(0,o.jsx)(n.h2,{id:"error-retry",children:"Error retry"}),"\n",(0,o.jsxs)(n.p,{children:["Data response: ",(0,o.jsx)(n.code,{children:'{"status":"success"}'})," or ",(0,o.jsx)(n.code,{children:'{"status":"Success: test request received"}'})," (case-sensitive,the return value required for a successful callback), returning other values is considered a failure. After failure, retry within 1 minute and 3 minutes."]})]})}function u(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},8175:(e,n,t)=>{t.d(n,{A:()=>r});t(6540);var i=t(5872),o=t(4848);function r(){let e=(0,i.K)()();return["newoaks.ai","www.newoaks.ai","eu.newoaks.ai"].includes(e)&&(e="NewOaks AI"),"appointify.ai"===e&&(e="Appointify AI"),(0,o.jsx)("code",{children:e})}},9357:(e,n,t)=>{t.d(n,{A:()=>s});t(6540);var i=t(5872),o=t(5363),r=t(4848);function s(e){let{children:n}=e;return(0,r.jsx)(o.A,{children:()=>{const e=(0,i.K)()();if("function"==typeof n){const t=n(e);return(0,r.jsx)("div",{className:"markdown markdown--section",children:t})}return(0,r.jsx)("code",{children:e})}})}},5872:(e,n,t)=>{function i(){return function(){return"undefined"==typeof window?"":window.location.hostname}}t.d(n,{K:()=>i})},8453:(e,n,t)=>{t.d(n,{R:()=>s,x:()=>a});var i=t(6540);const o={},r=i.createContext(o);function s(e){const n=i.useContext(r);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),i.createElement(r.Provider,{value:n},e.children)}}}]);