[{"data":1,"prerenderedAt":722},["ShallowReactive",2],{"navigation":3,"\u002Fwebhooks":43,"\u002Fwebhooks-surround":718},[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":712,"extension":713,"meta":714,"navigation":715,"path":30,"seo":716,"stem":31,"__hash__":717},"docs\u002Fwebhooks.md",{"type":46,"value":47,"toc":708},"minimark",[48,80,84,95,163,174,507,511,704],[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#set_webhook_url",[57,58,59],"code",{},"client.user.set_webhook_url",". 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#webhook_logs",[57,77,78],{},"client.user.webhook_logs",".",[81,82,83],"h2",{"id":83},"parse_webhook",[49,85,86,87,90,91,94],{},"Parse an inbound webhook body from JSON text (",[57,88,89],{},"str"," or ",[57,92,93],{},"bytes",") or an already parsed dict.",[96,97,102],"pre",{"className":98,"code":99,"language":100,"meta":101,"style":101},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","def parse_webhook(payload: str | bytes | Mapping[str, Any]) -> WebhookPayload\n","python","",[57,103,104],{"__ignoreMap":101},[105,106,108,112,116,120,124,127,131,134,137,139,143,146,148,151,154,157,160],"span",{"class":107,"line":12},"line",[105,109,111],{"class":110},"spNyl","def",[105,113,115],{"class":114},"s2Zo4"," parse_webhook",[105,117,119],{"class":118},"sMK4o","(",[105,121,123],{"class":122},"sHdIc","payload",[105,125,126],{"class":118},":",[105,128,130],{"class":129},"sBMFI"," str",[105,132,133],{"class":118}," |",[105,135,136],{"class":129}," bytes",[105,138,133],{"class":118},[105,140,142],{"class":141},"sTEyZ"," Mapping",[105,144,145],{"class":118},"[",[105,147,89],{"class":129},[105,149,150],{"class":118},",",[105,152,153],{"class":141}," Any",[105,155,156],{"class":118},"])",[105,158,159],{"class":118}," ->",[105,161,162],{"class":141}," WebhookPayload\n",[49,164,165,166,169,170,173],{},"Lenient: numeric fields may arrive as strings, missing or malformed fields become ",[57,167,168],{},"None",", unknown fields are dropped. It raises ",[57,171,172],{},"OnlineSimError"," only when the input is not a JSON object.",[96,175,177],{"className":98,"code":176,"language":100,"meta":101,"style":101},"from http.server import BaseHTTPRequestHandler, HTTPServer\n\nfrom onlinesimru import parse_webhook\n\n\nclass Hook(BaseHTTPRequestHandler):\n    def do_POST(self) -> None:\n        body = self.rfile.read(int(self.headers[\"Content-Length\"]))\n        hook = parse_webhook(body)\n        if hook[\"webhook_type\"] == \"receiving_sms\":\n            print(hook[\"operation_id\"], hook[\"code\"])\n        self.send_response(200)\n        self.end_headers()\n        self.wfile.write(b\"ok\")\n\n\nHTTPServer((\"\", 8080), Hook).serve_forever()\n",[57,178,179,204,210,222,226,230,246,268,319,337,370,406,425,438,467,472,477],{"__ignoreMap":101},[105,180,181,185,188,190,193,196,199,201],{"class":107,"line":12},[105,182,184],{"class":183},"s7zQu","from",[105,186,187],{"class":141}," http",[105,189,79],{"class":118},[105,191,192],{"class":141},"server ",[105,194,195],{"class":183},"import",[105,197,198],{"class":141}," BaseHTTPRequestHandler",[105,200,150],{"class":118},[105,202,203],{"class":141}," HTTPServer\n",[105,205,206],{"class":107,"line":17},[105,207,209],{"emptyLinePlaceholder":208},true,"\n",[105,211,212,214,217,219],{"class":107,"line":22},[105,213,184],{"class":183},[105,215,216],{"class":141}," onlinesimru ",[105,218,195],{"class":183},[105,220,221],{"class":141}," parse_webhook\n",[105,223,224],{"class":107,"line":27},[105,225,209],{"emptyLinePlaceholder":208},[105,227,228],{"class":107,"line":32},[105,229,209],{"emptyLinePlaceholder":208},[105,231,232,235,238,240,243],{"class":107,"line":37},[105,233,234],{"class":110},"class",[105,236,237],{"class":129}," Hook",[105,239,119],{"class":118},[105,241,242],{"class":129},"BaseHTTPRequestHandler",[105,244,245],{"class":118},"):\n",[105,247,248,251,254,256,260,263,265],{"class":107,"line":42},[105,249,250],{"class":110},"    def",[105,252,253],{"class":114}," do_POST",[105,255,119],{"class":118},[105,257,259],{"class":258},"s5tWE","self",[105,261,262],{"class":118},")",[105,264,159],{"class":118},[105,266,267],{"class":118}," None:\n",[105,269,271,274,277,280,282,286,288,291,293,296,298,300,302,305,307,310,314,316],{"class":107,"line":270},8,[105,272,273],{"class":141},"        body ",[105,275,276],{"class":118},"=",[105,278,279],{"class":141}," self",[105,281,79],{"class":118},[105,283,285],{"class":284},"swJcz","rfile",[105,287,79],{"class":118},[105,289,290],{"class":114},"read",[105,292,119],{"class":118},[105,294,295],{"class":129},"int",[105,297,119],{"class":118},[105,299,259],{"class":141},[105,301,79],{"class":118},[105,303,304],{"class":284},"headers",[105,306,145],{"class":118},[105,308,309],{"class":118},"\"",[105,311,313],{"class":312},"sfazB","Content-Length",[105,315,309],{"class":118},[105,317,318],{"class":118},"]))\n",[105,320,322,325,327,329,331,334],{"class":107,"line":321},9,[105,323,324],{"class":141},"        hook ",[105,326,276],{"class":118},[105,328,115],{"class":114},[105,330,119],{"class":118},[105,332,333],{"class":114},"body",[105,335,336],{"class":118},")\n",[105,338,340,343,346,348,350,352,354,357,360,363,365,367],{"class":107,"line":339},10,[105,341,342],{"class":183},"        if",[105,344,345],{"class":141}," hook",[105,347,145],{"class":118},[105,349,309],{"class":118},[105,351,63],{"class":312},[105,353,309],{"class":118},[105,355,356],{"class":118},"]",[105,358,359],{"class":118}," ==",[105,361,362],{"class":118}," \"",[105,364,67],{"class":312},[105,366,309],{"class":118},[105,368,369],{"class":118},":\n",[105,371,373,376,378,381,383,385,388,390,393,395,397,399,401,403],{"class":107,"line":372},11,[105,374,375],{"class":114},"            print",[105,377,119],{"class":118},[105,379,380],{"class":114},"hook",[105,382,145],{"class":118},[105,384,309],{"class":118},[105,386,387],{"class":312},"operation_id",[105,389,309],{"class":118},[105,391,392],{"class":118},"],",[105,394,345],{"class":114},[105,396,145],{"class":118},[105,398,309],{"class":118},[105,400,57],{"class":312},[105,402,309],{"class":118},[105,404,405],{"class":118},"])\n",[105,407,409,412,414,417,419,423],{"class":107,"line":408},12,[105,410,411],{"class":141},"        self",[105,413,79],{"class":118},[105,415,416],{"class":114},"send_response",[105,418,119],{"class":118},[105,420,422],{"class":421},"sbssI","200",[105,424,336],{"class":118},[105,426,428,430,432,435],{"class":107,"line":427},13,[105,429,411],{"class":141},[105,431,79],{"class":118},[105,433,434],{"class":114},"end_headers",[105,436,437],{"class":118},"()\n",[105,439,441,443,445,448,450,453,455,458,460,463,465],{"class":107,"line":440},14,[105,442,411],{"class":141},[105,444,79],{"class":118},[105,446,447],{"class":284},"wfile",[105,449,79],{"class":118},[105,451,452],{"class":114},"write",[105,454,119],{"class":118},[105,456,457],{"class":110},"b",[105,459,309],{"class":118},[105,461,462],{"class":312},"ok",[105,464,309],{"class":118},[105,466,336],{"class":118},[105,468,470],{"class":107,"line":469},15,[105,471,209],{"emptyLinePlaceholder":208},[105,473,475],{"class":107,"line":474},16,[105,476,209],{"emptyLinePlaceholder":208},[105,478,480,483,486,489,491,494,497,499,502,505],{"class":107,"line":479},17,[105,481,482],{"class":114},"HTTPServer",[105,484,485],{"class":118},"((",[105,487,488],{"class":118},"\"\"",[105,490,150],{"class":118},[105,492,493],{"class":421}," 8080",[105,495,496],{"class":118},"),",[105,498,237],{"class":114},[105,500,501],{"class":118},").",[105,503,504],{"class":114},"serve_forever",[105,506,437],{"class":118},[81,508,510],{"id":509},"payload-fields","Payload fields",[512,513,514,530],"table",{},[515,516,517],"thead",{},[518,519,520,524,527],"tr",{},[521,522,523],"th",{},"Field",[521,525,526],{},"Type",[521,528,529],{},"Description",[531,532,533,548,565,579,593,626,643,657,673,690],"tbody",{},[518,534,535,540,545],{},[536,537,538],"td",{},[57,539,63],{},[536,541,542],{},[57,543,544],{},"\"receiving_sms\" | \"rent_sms\" | None",[536,546,547],{},"Kind of operation.",[518,549,550,554,559],{},[536,551,552],{},[57,553,387],{},[536,555,556],{},[57,557,558],{},"int | None",[536,560,561,564],{},[57,562,563],{},"tzid"," of the operation or rent.",[518,566,567,572,576],{},[536,568,569],{},[57,570,571],{},"user_id",[536,573,574],{},[57,575,558],{},[536,577,578],{},"Account id.",[518,580,581,586,590],{},[536,582,583],{},[57,584,585],{},"country_code",[536,587,588],{},[57,589,558],{},[536,591,592],{},"Country code of the number.",[518,594,595,600,605],{},[536,596,597],{},[57,598,599],{},"number",[536,601,602],{},[57,603,604],{},"str | None",[536,606,607,608,611,612,615,616,619,620,622,623,501],{},"Numbers: ",[57,609,610],{},"+"," and the full number (",[57,613,614],{},"+79001234567","), or ",[57,617,618],{},"hidden",". Rent: the full number in digits without ",[57,621,610],{}," (",[57,624,625],{},"79001234567",[518,627,628,633,637],{},[536,629,630],{},[57,631,632],{},"sender",[536,634,635],{},[57,636,604],{},[536,638,639,640,79],{},"Sender of the SMS, e.g. ",[57,641,642],{},"VK",[518,644,645,650,654],{},[536,646,647],{},[57,648,649],{},"message",[536,651,652],{},[57,653,604],{},[536,655,656],{},"Full SMS text.",[518,658,659,663,667],{},[536,660,661],{},[57,662,57],{},[536,664,665],{},[57,666,604],{},[536,668,669,670,672],{},"Code extracted from the SMS; ",[57,671,488],{}," when none was found.",[518,674,675,680,684],{},[536,676,677],{},[57,678,679],{},"time_start",[536,681,682],{},[57,683,604],{},[536,685,686,687,79],{},"Numbers: when the operation was ordered. Rent: when the SMS arrived. ",[57,688,689],{},"YYYY-MM-DD HH:MM:SS",[518,691,692,697,701],{},[536,693,694],{},[57,695,696],{},"time_left",[536,698,699],{},[57,700,558],{},[536,702,703],{},"Time left: seconds for numbers, minutes for rent.",[705,706,707],"style",{},"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 .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}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 .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}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 .s5tWE, html code.shiki .s5tWE{--shiki-light:#E53935;--shiki-light-font-style:italic;--shiki-default:#F07178;--shiki-default-font-style:italic;--shiki-dark:#F07178;--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 .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}",{"title":101,"searchDepth":17,"depth":17,"links":709},[710,711],{"id":83,"depth":17,"text":83},{"id":509,"depth":17,"text":510},"Receive SMS as HTTP callbacks and parse them with parse_webhook.","md",{},{"order":32},{"title":29,"description":712},"nvi2ZEEwxocU5MynDj7pm9yFkInHX7rYpVwEyEkzWw4",[719,721],{"title":19,"path":20,"stem":21,"description":720,"order":22},"Balance, profile, payments and the webhook URL — client.user.",null,1795164115454]