[{"data":1,"prerenderedAt":637},["ShallowReactive",2],{"navigation":3,"\u002Fwebhooks":43,"\u002Fwebhooks-surround":633},[4,8,13,18,23,28,33,38],{"title":5,"path":6,"stem":7},"Getting started","\u002F","index",{"title":9,"path":10,"stem":11,"order":12},"Numbers","\u002Fnumbers","numbers",1,{"title":14,"path":15,"stem":16,"order":17},"Rent","\u002Frent","rent",2,{"title":19,"path":20,"stem":21,"order":22},"User","\u002Fuser","user",3,{"title":24,"path":25,"stem":26,"order":27},"Free numbers","\u002Ffree","free",4,{"title":29,"path":30,"stem":31,"order":32},"Webhooks","\u002Fwebhooks","webhooks",5,{"title":34,"path":35,"stem":36,"order":37},"Testing","\u002Ftesting","testing",6,{"title":39,"path":40,"stem":41,"order":42},"Changelog","\u002Fchangelog","changelog",7,{"id":44,"title":29,"body":45,"description":627,"extension":628,"meta":629,"navigation":630,"path":30,"seo":631,"stem":31,"__hash__":632},"docs\u002Fwebhooks.md",{"type":46,"value":47,"toc":623},"minimark",[48,80,85,88,133,144,443,447,619],[49,50,51,52,60,61,64,65,68,69,72,73,79],"p",{},"Set a URL with ",[53,54,56],"a",{"href":55},"\u002Fuser#setwebhookurl",[57,58,59],"code",{},"client.user.setWebhookUrl",". For each SMS the server POSTs a JSON body to it: ",[57,62,63],{},"webhook_type"," ",[57,66,67],{},"receiving_sms"," for numbers, ",[57,70,71],{},"rent_sms"," for rents. Delivery attempts are listed by ",[53,74,76],{"href":75},"\u002Fuser#webhooklogs",[57,77,78],{},"client.user.webhookLogs",".",[81,82,84],"h2",{"id":83},"parsewebhook","parseWebhook",[49,86,87],{},"Parse an inbound webhook body from a JSON string or an already parsed object.",[89,90,95],"pre",{"className":91,"code":92,"language":93,"meta":94,"style":94},"language-ts shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","parseWebhook(payload: string | Record\u003Cstring, unknown>): WebhookPayload\n","ts","",[57,96,97],{"__ignoreMap":94},[98,99,101,104,108,112,115,118,121,124,127,130],"span",{"class":100,"line":12},"line",[98,102,84],{"class":103},"s2Zo4",[98,105,107],{"class":106},"sTEyZ","(payload: string ",[98,109,111],{"class":110},"sMK4o","|",[98,113,114],{"class":106}," Record",[98,116,117],{"class":110},"\u003C",[98,119,120],{"class":106},"string",[98,122,123],{"class":110},",",[98,125,126],{"class":106}," unknown",[98,128,129],{"class":110},">",[98,131,132],{"class":106},"): WebhookPayload\n",[49,134,135,136,139,140,143],{},"Lenient: numeric fields may arrive as strings, missing or malformed fields become ",[57,137,138],{},"null",", unknown fields are dropped. It throws ",[57,141,142],{},"OnlineSimError"," only when the input is not a JSON object.",[89,145,147],{"className":91,"code":146,"language":93,"meta":94,"style":94},"import { createServer } from 'node:http'\nimport { parseWebhook } from 'onlinesim-js-api'\n\ncreateServer((req, res) => {\n  let body = ''\n  req.on('data', (chunk) => (body += chunk))\n  req.on('end', () => {\n    const hook = parseWebhook(body)\n    if (hook.webhook_type === 'receiving_sms') console.log(hook.operation_id, hook.code)\n    res.end('ok')\n  })\n}).listen(8080)\n",[57,148,149,177,197,203,232,246,293,319,339,393,414,422],{"__ignoreMap":94},[98,150,151,155,158,161,164,167,170,174],{"class":100,"line":12},[98,152,154],{"class":153},"s7zQu","import",[98,156,157],{"class":110}," {",[98,159,160],{"class":106}," createServer",[98,162,163],{"class":110}," }",[98,165,166],{"class":153}," from",[98,168,169],{"class":110}," '",[98,171,173],{"class":172},"sfazB","node:http",[98,175,176],{"class":110},"'\n",[98,178,179,181,183,186,188,190,192,195],{"class":100,"line":17},[98,180,154],{"class":153},[98,182,157],{"class":110},[98,184,185],{"class":106}," parseWebhook",[98,187,163],{"class":110},[98,189,166],{"class":153},[98,191,169],{"class":110},[98,193,194],{"class":172},"onlinesim-js-api",[98,196,176],{"class":110},[98,198,199],{"class":100,"line":22},[98,200,202],{"emptyLinePlaceholder":201},true,"\n",[98,204,205,208,211,213,217,219,222,225,229],{"class":100,"line":27},[98,206,207],{"class":103},"createServer",[98,209,210],{"class":106},"(",[98,212,210],{"class":110},[98,214,216],{"class":215},"sHdIc","req",[98,218,123],{"class":110},[98,220,221],{"class":215}," res",[98,223,224],{"class":110},")",[98,226,228],{"class":227},"spNyl"," =>",[98,230,231],{"class":110}," {\n",[98,233,234,237,240,243],{"class":100,"line":32},[98,235,236],{"class":227},"  let",[98,238,239],{"class":106}," body",[98,241,242],{"class":110}," =",[98,244,245],{"class":110}," ''\n",[98,247,248,251,253,256,259,262,265,267,269,272,275,277,279,281,284,287,290],{"class":100,"line":37},[98,249,250],{"class":106},"  req",[98,252,79],{"class":110},[98,254,255],{"class":103},"on",[98,257,210],{"class":258},"swJcz",[98,260,261],{"class":110},"'",[98,263,264],{"class":172},"data",[98,266,261],{"class":110},[98,268,123],{"class":110},[98,270,271],{"class":110}," (",[98,273,274],{"class":215},"chunk",[98,276,224],{"class":110},[98,278,228],{"class":227},[98,280,271],{"class":258},[98,282,283],{"class":106},"body",[98,285,286],{"class":110}," +=",[98,288,289],{"class":106}," chunk",[98,291,292],{"class":258},"))\n",[98,294,295,297,299,301,303,305,308,310,312,315,317],{"class":100,"line":42},[98,296,250],{"class":106},[98,298,79],{"class":110},[98,300,255],{"class":103},[98,302,210],{"class":258},[98,304,261],{"class":110},[98,306,307],{"class":172},"end",[98,309,261],{"class":110},[98,311,123],{"class":110},[98,313,314],{"class":110}," ()",[98,316,228],{"class":227},[98,318,231],{"class":110},[98,320,322,325,328,330,332,334,336],{"class":100,"line":321},8,[98,323,324],{"class":227},"    const",[98,326,327],{"class":106}," hook",[98,329,242],{"class":110},[98,331,185],{"class":103},[98,333,210],{"class":258},[98,335,283],{"class":106},[98,337,338],{"class":258},")\n",[98,340,342,345,347,350,352,354,357,359,361,363,366,369,371,374,376,378,380,383,385,387,389,391],{"class":100,"line":341},9,[98,343,344],{"class":153},"    if",[98,346,271],{"class":258},[98,348,349],{"class":106},"hook",[98,351,79],{"class":110},[98,353,63],{"class":106},[98,355,356],{"class":110}," ===",[98,358,169],{"class":110},[98,360,67],{"class":172},[98,362,261],{"class":110},[98,364,365],{"class":258},") ",[98,367,368],{"class":106},"console",[98,370,79],{"class":110},[98,372,373],{"class":103},"log",[98,375,210],{"class":258},[98,377,349],{"class":106},[98,379,79],{"class":110},[98,381,382],{"class":106},"operation_id",[98,384,123],{"class":110},[98,386,327],{"class":106},[98,388,79],{"class":110},[98,390,57],{"class":106},[98,392,338],{"class":258},[98,394,396,399,401,403,405,407,410,412],{"class":100,"line":395},10,[98,397,398],{"class":106},"    res",[98,400,79],{"class":110},[98,402,307],{"class":103},[98,404,210],{"class":258},[98,406,261],{"class":110},[98,408,409],{"class":172},"ok",[98,411,261],{"class":110},[98,413,338],{"class":258},[98,415,417,420],{"class":100,"line":416},11,[98,418,419],{"class":110},"  }",[98,421,338],{"class":258},[98,423,425,428,430,432,435,437,441],{"class":100,"line":424},12,[98,426,427],{"class":110},"}",[98,429,224],{"class":106},[98,431,79],{"class":110},[98,433,434],{"class":103},"listen",[98,436,210],{"class":106},[98,438,440],{"class":439},"sbssI","8080",[98,442,338],{"class":106},[81,444,446],{"id":445},"payload-fields","Payload fields",[448,449,450,466],"table",{},[451,452,453],"thead",{},[454,455,456,460,463],"tr",{},[457,458,459],"th",{},"Field",[457,461,462],{},"Type",[457,464,465],{},"Description",[467,468,469,484,501,515,529,547,564,578,591,605],"tbody",{},[454,470,471,476,481],{},[472,473,474],"td",{},[57,475,63],{},[472,477,478],{},[57,479,480],{},"'receiving_sms' | 'rent_sms' | null",[472,482,483],{},"Kind of operation.",[454,485,486,490,495],{},[472,487,488],{},[57,489,382],{},[472,491,492],{},[57,493,494],{},"number | null",[472,496,497,500],{},[57,498,499],{},"tzid"," of the operation or rent.",[454,502,503,508,512],{},[472,504,505],{},[57,506,507],{},"user_id",[472,509,510],{},[57,511,494],{},[472,513,514],{},"Account id.",[454,516,517,522,526],{},[472,518,519],{},[57,520,521],{},"country_code",[472,523,524],{},[57,525,494],{},[472,527,528],{},"Country code of the number.",[454,530,531,536,541],{},[472,532,533],{},[57,534,535],{},"number",[472,537,538],{},[57,539,540],{},"string | null",[472,542,543,544,79],{},"The number, e.g. ",[57,545,546],{},"+79001234567",[454,548,549,554,558],{},[472,550,551],{},[57,552,553],{},"sender",[472,555,556],{},[57,557,540],{},[472,559,560,561,79],{},"Sender of the SMS, e.g. ",[57,562,563],{},"VK",[454,565,566,571,575],{},[472,567,568],{},[57,569,570],{},"message",[472,572,573],{},[57,574,540],{},[472,576,577],{},"Full SMS text.",[454,579,580,584,588],{},[472,581,582],{},[57,583,57],{},[472,585,586],{},[57,587,540],{},[472,589,590],{},"Code extracted from the SMS.",[454,592,593,598,602],{},[472,594,595],{},[57,596,597],{},"time_start",[472,599,600],{},[57,601,540],{},[472,603,604],{},"Start of the operation.",[454,606,607,612,616],{},[472,608,609],{},[57,610,611],{},"time_left",[472,613,614],{},[57,615,494],{},[472,617,618],{},"Time left.",[620,621,622],"style",{},"html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}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 .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 .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 .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}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 .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}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}",{"title":94,"searchDepth":17,"depth":17,"links":624},[625,626],{"id":83,"depth":17,"text":84},{"id":445,"depth":17,"text":446},"Receive SMS as HTTP callbacks and parse them with parseWebhook.","md",{},{"order":32},{"title":29,"description":627},"waK9wHm1vWdSnzTM41PFqwk2Pxrrb9gII9p7meUh9e0",[634,636],{"title":19,"path":20,"stem":21,"description":635,"order":22},"Balance, profile, payments and the webhook URL — client.user.",null,1795107813731]