[{"data":1,"prerenderedAt":622},["ShallowReactive",2],{"navigation":3,"\u002Fwebhooks":43,"\u002Fwebhooks-surround":618},[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":612,"extension":613,"meta":614,"navigation":615,"path":30,"seo":616,"stem":31,"__hash__":617},"docs\u002Fwebhooks.md",{"type":46,"value":47,"toc":608},"minimark",[48,80,85,92,127,138,389,393,598,604],[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,88,91],{},"Parse an inbound webhook body. A top-level function (not ",[57,89,90],{},"suspend","): no client needed.",[93,94,99],"pre",{"className":95,"code":96,"language":97,"meta":98,"style":98},"language-kotlin shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","fun parseWebhook(json: String): WebhookPayload\n","kotlin","",[57,100,101],{"__ignoreMap":98},[102,103,105,109,113,117,121,124],"span",{"class":104,"line":12},"line",[102,106,108],{"class":107},"sMK4o","fun",[102,110,112],{"class":111},"s2Zo4"," parseWebhook",[102,114,116],{"class":115},"sTEyZ","(json: ",[102,118,120],{"class":119},"sBMFI","String",[102,122,123],{"class":115},"): ",[102,125,126],{"class":119},"WebhookPayload\n",[49,128,129,130,133,134,137],{},"Lenient: numeric fields may arrive as strings, missing or malformed fields become ",[57,131,132],{},"null",", unknown fields are dropped. It throws ",[57,135,136],{},"OnlineSimException"," only when the input is not a JSON object.",[93,139,141],{"className":95,"code":140,"language":97,"meta":98,"style":98},"import com.sun.net.httpserver.HttpServer\nimport java.net.InetSocketAddress\nimport ru.onlinesim.kotlin.parseWebhook\n\nfun main() {\n    val server = HttpServer.create(InetSocketAddress(8080), 0)\n    server.createContext(\"\u002Fonlinesim-hook\") { exchange ->\n        val hook = parseWebhook(exchange.requestBody.readBytes().decodeToString())\n        if (hook.webhookType() == \"receiving_sms\") println(\"${hook.operationId()} ${hook.code()}\")\n        exchange.sendResponseHeaders(200, -1)\n        exchange.close()\n    }\n    server.start()\n}\n",[57,142,143,151,158,165,171,181,219,240,268,331,356,367,373,383],{"__ignoreMap":98},[102,144,145,148],{"class":104,"line":12},[102,146,147],{"class":107},"import",[102,149,150],{"class":119}," com.sun.net.httpserver.HttpServer\n",[102,152,153,155],{"class":104,"line":17},[102,154,147],{"class":107},[102,156,157],{"class":119}," java.net.InetSocketAddress\n",[102,159,160,162],{"class":104,"line":22},[102,161,147],{"class":107},[102,163,164],{"class":119}," ru.onlinesim.kotlin.parseWebhook\n",[102,166,167],{"class":104,"line":27},[102,168,170],{"emptyLinePlaceholder":169},true,"\n",[102,172,173,175,178],{"class":104,"line":32},[102,174,108],{"class":107},[102,176,177],{"class":111}," main",[102,179,180],{"class":115},"() {\n",[102,182,183,186,189,192,195,198,201,204,206,210,213,216],{"class":104,"line":37},[102,184,185],{"class":107},"    val",[102,187,188],{"class":115}," server ",[102,190,191],{"class":107},"=",[102,193,194],{"class":115}," HttpServer.",[102,196,197],{"class":111},"create",[102,199,200],{"class":115},"(",[102,202,203],{"class":111},"InetSocketAddress",[102,205,200],{"class":115},[102,207,209],{"class":208},"sbssI","8080",[102,211,212],{"class":115},"), ",[102,214,215],{"class":208},"0",[102,217,218],{"class":115},")\n",[102,220,221,224,227,229,233,236],{"class":104,"line":42},[102,222,223],{"class":115},"    server.",[102,225,226],{"class":111},"createContext",[102,228,200],{"class":115},[102,230,232],{"class":231},"sfazB","\"\u002Fonlinesim-hook\"",[102,234,235],{"class":115},") { exchange ",[102,237,239],{"class":238},"spNyl","->\n",[102,241,243,246,249,251,253,256,259,262,265],{"class":104,"line":242},8,[102,244,245],{"class":107},"        val",[102,247,248],{"class":115}," hook ",[102,250,191],{"class":107},[102,252,112],{"class":111},[102,254,255],{"class":115},"(exchange.requestBody.",[102,257,258],{"class":111},"readBytes",[102,260,261],{"class":115},"().",[102,263,264],{"class":111},"decodeToString",[102,266,267],{"class":115},"())\n",[102,269,271,275,278,281,284,287,290,293,296,298,301,304,307,310,313,316,319,321,323,325,327,329],{"class":104,"line":270},9,[102,272,274],{"class":273},"s7zQu","        if",[102,276,277],{"class":115}," (hook.",[102,279,280],{"class":111},"webhookType",[102,282,283],{"class":115},"() ",[102,285,286],{"class":107},"==",[102,288,289],{"class":231}," \"receiving_sms\"",[102,291,292],{"class":115},") ",[102,294,295],{"class":111},"println",[102,297,200],{"class":115},[102,299,300],{"class":231},"\"",[102,302,303],{"class":107},"${",[102,305,306],{"class":115},"hook.",[102,308,309],{"class":111},"operationId",[102,311,312],{"class":115},"()",[102,314,315],{"class":107},"}",[102,317,318],{"class":107}," ${",[102,320,306],{"class":115},[102,322,57],{"class":111},[102,324,312],{"class":115},[102,326,315],{"class":107},[102,328,300],{"class":231},[102,330,218],{"class":115},[102,332,334,337,340,342,345,348,351,354],{"class":104,"line":333},10,[102,335,336],{"class":115},"        exchange.",[102,338,339],{"class":111},"sendResponseHeaders",[102,341,200],{"class":115},[102,343,344],{"class":208},"200",[102,346,347],{"class":115},", ",[102,349,350],{"class":107},"-",[102,352,353],{"class":208},"1",[102,355,218],{"class":115},[102,357,359,361,364],{"class":104,"line":358},11,[102,360,336],{"class":115},[102,362,363],{"class":111},"close",[102,365,366],{"class":115},"()\n",[102,368,370],{"class":104,"line":369},12,[102,371,372],{"class":115},"    }\n",[102,374,376,378,381],{"class":104,"line":375},13,[102,377,223],{"class":115},[102,379,380],{"class":111},"start",[102,382,366],{"class":115},[102,384,386],{"class":104,"line":385},14,[102,387,388],{"class":115},"}\n",[81,390,392],{"id":391},"payload-fields","Payload fields",[394,395,396,412],"table",{},[397,398,399],"thead",{},[400,401,402,406,409],"tr",{},[403,404,405],"th",{},"Accessor",[403,407,408],{},"Type",[403,410,411],{},"Description",[413,414,415,438,456,470,485,518,535,549,567,584],"tbody",{},[400,416,417,423,428],{},[418,419,420],"td",{},[57,421,422],{},"webhookType()",[418,424,425],{},[57,426,427],{},"String?",[418,429,430,347,432,434,435,437],{},[57,431,67],{},[57,433,71],{},", or ",[57,436,132],{}," for anything else.",[400,439,440,445,450],{},[418,441,442],{},[57,443,444],{},"operationId()",[418,446,447],{},[57,448,449],{},"Long?",[418,451,452,455],{},[57,453,454],{},"tzid"," of the operation or rent.",[400,457,458,463,467],{},[418,459,460],{},[57,461,462],{},"userId()",[418,464,465],{},[57,466,449],{},[418,468,469],{},"Account id.",[400,471,472,477,482],{},[418,473,474],{},[57,475,476],{},"countryCode()",[418,478,479],{},[57,480,481],{},"Int?",[418,483,484],{},"Country code of the number.",[400,486,487,492,496],{},[418,488,489],{},[57,490,491],{},"number()",[418,493,494],{},[57,495,427],{},[418,497,498,499,502,503,506,507,510,511,513,514,517],{},"Numbers: ",[57,500,501],{},"+"," and the full number (",[57,504,505],{},"+79001234567","), or ",[57,508,509],{},"hidden",". Rent: the full number in digits without ",[57,512,501],{}," (",[57,515,516],{},"79001234567",").",[400,519,520,525,529],{},[418,521,522],{},[57,523,524],{},"sender()",[418,526,527],{},[57,528,427],{},[418,530,531,532,79],{},"Sender of the SMS, e.g. ",[57,533,534],{},"VK",[400,536,537,542,546],{},[418,538,539],{},[57,540,541],{},"message()",[418,543,544],{},[57,545,427],{},[418,547,548],{},"Full SMS text.",[400,550,551,556,560],{},[418,552,553],{},[57,554,555],{},"code()",[418,557,558],{},[57,559,427],{},[418,561,562,563,566],{},"Code extracted from the SMS; ",[57,564,565],{},"\"\""," when none was found.",[400,568,569,574,578],{},[418,570,571],{},[57,572,573],{},"timeStart()",[418,575,576],{},[57,577,427],{},[418,579,580,581,79],{},"Numbers: when the operation was ordered. Rent: when the SMS arrived. ",[57,582,583],{},"YYYY-MM-DD HH:MM:SS",[400,585,586,591,595],{},[418,587,588],{},[57,589,590],{},"timeLeft()",[418,592,593],{},[57,594,449],{},[418,596,597],{},"Time left: seconds for numbers, minutes for rent.",[49,599,600,601,603],{},"Every accessor returns ",[57,602,132],{}," when the field is missing or malformed.",[605,606,607],"style",{},"html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}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 .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}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 .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}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 .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}",{"title":98,"searchDepth":17,"depth":17,"links":609},[610,611],{"id":83,"depth":17,"text":84},{"id":391,"depth":17,"text":392},"Receive SMS as HTTP callbacks and parse them with parseWebhook.","md",{},{"order":32},{"title":29,"description":612},"rEmMI0lrTluf4v7HeiwujKIQUSKWAhzumXG01aMbu5I",[619,621],{"title":19,"path":20,"stem":21,"description":620,"order":22},"Balance, profile, payments and the webhook URL — client.user.",null,1795165467553]