[{"data":1,"prerenderedAt":1826},["ShallowReactive",2],{"\u002Farticles\u002Fwhatsapp-webhook-subscriptions":3},{"id":4,"title":5,"body":6,"date":1811,"description":1812,"extension":1813,"head":1814,"image":1815,"meta":1816,"navigation":725,"ogImage":1814,"path":1817,"rating":231,"readingTime":1818,"robots":1814,"schemaOrg":1814,"seo":1819,"sitemap":1820,"stem":1821,"tags":1822,"__hash__":1825},"articles_en\u002Farticles\u002Fwhatsapp-webhook-subscriptions.md","A WhatsApp Cloud API Gotcha: The Webhook Verifies, but No Messages Arrive",{"type":7,"value":8,"toc":1777},"minimark",[9,33,38,41,72,75,81,84,88,95,193,200,265,268,296,302,307,314,316,320,335,343,354,367,369,373,383,387,419,435,439,466,480,492,494,498,505,509,529,547,561,608,617,624,630,644,647,672,689,693,711,742,749,774,781,798,802,812,839,841,845,848,852,874,878,892,901,909,916,962,973,977,995,999,1010,1078,1080,1084,1091,1149,1152,1174,1177,1181,1191,1216,1220,1231,1233,1237,1240,1300,1304,1366,1376,1378,1382,1401,1761,1773],[10,11,12,21],"note",{},[13,14,15,16,20],"p",{},"You followed the docs step by step and set up the WhatsApp Cloud API webhook. The Meta console plainly says \"verified\", and a message sent from a real phone shows ✓✓ (delivered). Yet your backend logs contain ",[17,18,19],"strong",{},"not a single inbound record",".",[13,22,23,24,28,29,32],{},"If this is where you are stuck, this post can save you a few hours. The cause is almost always one switch that the docs barely emphasize but that decides whether messages flow at all: ",[25,26,27],"code",{},"subscribed_apps",". I'll untangle the ",[17,30,31],{},"three things that are all called a \"subscription\" but are entirely different"," in the WhatsApp Cloud API, and give you a systematic debugging path that doesn't rely on guessing.",[34,35,37],"h2",{"id":36},"_1-the-symptom-a-counterintuitive-delivered","1. The symptom: a counterintuitive \"delivered\"",[13,39,40],{},"After integrating the WhatsApp Cloud API and configuring the webhook per the official Quickstart, a common place to get stuck looks like this:",[42,43,44,55,65],"ul",{},[45,46,47,48,51,52,20],"li",{},"You click ",[17,49,50],{},"Verify and save"," in the Meta developer console, and it reports the webhook as ",[17,53,54],{},"verified",[45,56,57,58,61,62,20],{},"You send ",[25,59,60],{},"hello"," from a real phone to your WhatsApp number, and the message shows ",[17,63,64],{},"✓✓ (delivered)",[45,66,67,68,71],{},"But your backend ",[17,69,70],{},"receives no POST callback at all",", and the inbound log is empty.",[13,73,74],{},"Verification succeeded, the message was delivered, and still no callback. At this point most people start suspecting the reverse proxy, or the signature check swallowing the message, or a missing payment method.",[13,76,77,80],{},[17,78,79],{},"It is most likely none of those."," The real cause is that you missed the most important, and best hidden, of the three \"subscriptions\" in the WhatsApp Cloud API.",[82,83],"hr",{},[34,85,87],{"id":86},"_2-the-core-idea-three-things-called-subscription-that-are-three-different-things","2. The core idea: three things called \"subscription\" that are three different things",[13,89,90,91,94],{},"For an inbound message to reach your backend, three conditions have to hold on Meta's side at the same time. The trap is that all three ",[17,92,93],{},"carry the word \"subscribe\""," in the docs and the console, so they are easy to conflate, and doing one feels like having done them all.",[96,97,98,117],"table",{},[99,100,101],"thead",{},[102,103,104,108,111,114],"tr",{},[105,106,107],"th",{},"#",[105,109,110],{},"Name",[105,112,113],{},"Where you do it",[105,115,116],{},"What it actually does",[118,119,120,146,166],"tbody",{},[102,121,122,126,136,139],{},[123,124,125],"td",{},"①",[123,127,128,131,132,135],{},[17,129,130],{},"Webhook URL verification"," (the ",[25,133,134],{},"hub.mode=subscribe"," challenge)",[123,137,138],{},"Your code (a GET endpoint)",[123,140,141,142,145],{},"Proves the callback URL is reachable and the ",[25,143,144],{},"verify_token"," is correct",[102,147,148,151,160,163],{},[123,149,150],{},"②",[123,152,153],{},[17,154,155,156,159],{},"App subscription to the ",[25,157,158],{},"messages"," field",[123,161,162],{},"Meta console → the App's Webhooks settings",[123,164,165],{},"The App declares which kinds of events it wants to receive",[102,167,168,171,180,186],{},[123,169,170],{},"③",[123,172,173,176,177,179],{},[17,174,175],{},"WABA → App subscription"," (",[25,178,27],{},")",[123,181,182,183,179],{},"Meta platform API (",[17,184,185],{},"not a checkbox in the console",[123,187,188,189,192],{},"Routes ",[17,190,191],{},"the events of a specific WhatsApp Business Account"," to this App",[13,194,195,196,199],{},"The diagram below shows the three gates a message has to pass through to reach your backend. Without ③, Meta ",[17,197,198],{},"drops it silently",", and the sender notices nothing:",[201,202,207],"pre",{"className":203,"code":204,"language":205,"meta":206,"style":206},"language-mermaid shiki shiki-themes github-light github-dark github-dark","flowchart TD\n    U[\"User sends a message from a real phone\"] --> M[\"Meta Cloud API\"]\n    M --> G1{\"① Callback URL verified?\u003Cbr>(reachable + verify_token matches)\"}\n    G1 -->|No| X1[\"Callback verification fails\"]\n    G1 -->|Yes| G2{\"② App subscribed to the messages field?\"}\n    G2 -->|No| X2[\"App does not receive this event type\"]\n    G2 -->|Yes| G3{\"③ subscribed_apps:\u003Cbr>is the WABA subscribed to this App?\"}\n    G3 -->|No| X3[\"⚠ Meta silently does not deliver\u003Cbr>(the one most often missed)\"]\n    G3 -->|Yes| OK[\"✅ POST to your backend webhook\"]\n","mermaid","",[25,208,209,217,223,229,235,241,247,253,259],{"__ignoreMap":206},[210,211,214],"span",{"class":212,"line":213},"line",1,[210,215,216],{},"flowchart TD\n",[210,218,220],{"class":212,"line":219},2,[210,221,222],{},"    U[\"User sends a message from a real phone\"] --> M[\"Meta Cloud API\"]\n",[210,224,226],{"class":212,"line":225},3,[210,227,228],{},"    M --> G1{\"① Callback URL verified?\u003Cbr>(reachable + verify_token matches)\"}\n",[210,230,232],{"class":212,"line":231},4,[210,233,234],{},"    G1 -->|No| X1[\"Callback verification fails\"]\n",[210,236,238],{"class":212,"line":237},5,[210,239,240],{},"    G1 -->|Yes| G2{\"② App subscribed to the messages field?\"}\n",[210,242,244],{"class":212,"line":243},6,[210,245,246],{},"    G2 -->|No| X2[\"App does not receive this event type\"]\n",[210,248,250],{"class":212,"line":249},7,[210,251,252],{},"    G2 -->|Yes| G3{\"③ subscribed_apps:\u003Cbr>is the WABA subscribed to this App?\"}\n",[210,254,256],{"class":212,"line":255},8,[210,257,258],{},"    G3 -->|No| X3[\"⚠ Meta silently does not deliver\u003Cbr>(the one most often missed)\"]\n",[210,260,262],{"class":212,"line":261},9,[210,263,264],{},"    G3 -->|Yes| OK[\"✅ POST to your backend webhook\"]\n",[13,266,267],{},"A mail analogy makes it clear:",[10,269,270,275,280,289],{},[13,271,272,274],{},[17,273,125],{}," = the post office confirms that your address really exists and can receive mail.",[13,276,277,279],{},[17,278,150],{}," = you declare that you only want registered mail, not flyers.",[13,281,282,284,285,288],{},[17,283,170],{}," = ",[17,286,287],{},"a specific sender"," is registered so that the mail they send gets delivered to your address.",[13,290,291,292,295],{},"Without ③, the address is verified and the mail type is declared, but ",[17,293,294],{},"no sender is registered to you",", so the mail never comes.",[13,297,298,299,20],{},"In the vast majority of \"verified but no messages\" cases, ① and ② are done and ",[17,300,301],{},"only ③ is missing",[303,304,306],"h3",{"id":305},"why-is-the-easiest-to-miss","Why is ③ the easiest to miss?",[13,308,309,310,313],{},"Because ① and ② both have prominent UI entry points in the console (enter the URL, click verify, tick the fields), and each ends with a success message. ③, on the other hand, ",[17,311,312],{},"often has no corresponding checkbox in the console","; you have to call the Graph API explicitly. In the docs it is usually a low-key section of the API Reference rather than part of the main Quickstart path, so it is very natural to skip.",[82,315],{},[34,317,319],{"id":318},"_3-why-does-it-work-in-testing-and-break-the-moment-you-go-to-production","3. Why does it work in testing and break the moment you go to production?",[13,321,322,323,326,327,330,331,334],{},"This is another frequent source of confusion, and the key to understanding ③. Many people use the ",[17,324,325],{},"test number"," Meta provides during the ",[17,328,329],{},"testing phase",", and everything works. Then they switch to ",[17,332,333],{},"their own production number and their own WABA",", and messages stop arriving immediately.",[13,336,337,338],{},"To understand this, remember one fact: ",[17,339,340,342],{},[25,341,27],{}," is a WABA-level subscription. It binds one specific WABA to one specific App, and it does not carry over automatically when you change numbers or environments.",[13,344,345,346,349,350,353],{},"So why did it work in testing? ",[17,347,348],{},"This is exactly the place where you should not take things for granted."," That subscription may have been established at some earlier point: perhaps an onboarding flow did it as a side effect, or perhaps someone configured it by hand when setting up the test environment and never wrote it into the handover notes. Either way you can't see that it exists, so you assume things were simply fine all along. It is not in your code, and it may not be in anyone's operation log either. So ",[17,351,352],{},"don't try to work out why testing worked (often you can't), and check the production environment directly"," (see section 4).",[355,356,357],"warning",{},[13,358,359,362,363,366],{},[17,360,361],{},"Conclusion",": a working test environment does not mean the chain is complete. For platform-side state such as subscriptions and registrations, which ",[17,364,365],{},"lives neither in your code nor in any step you explicitly performed",", you must confirm each item when you change environments. You cannot assume that production works because testing did.",[82,368],{},[34,370,372],{"id":371},"_4-how-to-check-for-and-how-to-fix-it","4. How to check for ③, and how to fix it",[13,374,375,376],{},"The rule of thumb in one line: ",[17,377,378,379,382],{},"WhatsApp webhook configured but no messages arriving → check ",[25,380,381],{},"GET \u002F{waba_id}\u002Fsubscribed_apps"," first.",[303,384,386],{"id":385},"_41-check-which-apps-is-this-waba-subscribed-to","4.1 Check: which Apps is this WABA subscribed to",[201,388,392],{"className":389,"code":390,"language":391,"meta":206,"style":206},"language-bash shiki shiki-themes github-light github-dark github-dark","curl -s \"https:\u002F\u002Fgraph.facebook.com\u002Fv17.0\u002F\u003CWABA_ID>\u002Fsubscribed_apps\" \\\n  -H \"Authorization: Bearer \u003CACCESS_TOKEN>\"\n","bash",[25,393,394,411],{"__ignoreMap":206},[210,395,396,400,404,408],{"class":212,"line":213},[210,397,399],{"class":398},"shcOC","curl",[210,401,403],{"class":402},"suiK_"," -s",[210,405,407],{"class":406},"sfrk1"," \"https:\u002F\u002Fgraph.facebook.com\u002Fv17.0\u002F\u003CWABA_ID>\u002Fsubscribed_apps\"",[210,409,410],{"class":402}," \\\n",[210,412,413,416],{"class":212,"line":219},[210,414,415],{"class":402},"  -H",[210,417,418],{"class":406}," \"Authorization: Bearer \u003CACCESS_TOKEN>\"\n",[42,420,421,432],{},[45,422,423,424,427,428,431],{},"It returns ",[25,425,426],{},"{\"data\": []}"," (an empty array) → ",[17,429,430],{},"this is it",". The WABA is not subscribed to any App, so of course nothing is delivered.",[45,433,434],{},"Your App is in the response → ③ is in place and the problem is elsewhere (go back and check signature verification, the reverse proxy, and the field subscription).",[303,436,438],{"id":437},"_42-fix-subscribe-the-waba-to-the-current-app","4.2 Fix: subscribe the WABA to the current App",[201,440,442],{"className":389,"code":441,"language":391,"meta":206,"style":206},"curl -s -X POST \"https:\u002F\u002Fgraph.facebook.com\u002Fv17.0\u002F\u003CWABA_ID>\u002Fsubscribed_apps\" \\\n  -H \"Authorization: Bearer \u003CACCESS_TOKEN>\"\n",[25,443,444,460],{"__ignoreMap":206},[210,445,446,448,450,453,456,458],{"class":212,"line":213},[210,447,399],{"class":398},[210,449,403],{"class":402},[210,451,452],{"class":402}," -X",[210,454,455],{"class":406}," POST",[210,457,407],{"class":406},[210,459,410],{"class":402},[210,461,462,464],{"class":212,"line":219},[210,463,415],{"class":402},[210,465,418],{"class":406},[13,467,468,469,472,473,476,477],{},"The \"App\" being subscribed here is the one that ",[25,470,471],{},"\u003CACCESS_TOKEN>"," belongs to. Once it returns ",[25,474,475],{},"{\"success\": true}",", ",[17,478,479],{},"send another message from a real phone, and the callback usually arrives right away.",[355,481,482],{},[13,483,484,485,487,488,491],{},"Make sure you use the right ",[25,486,471],{},". In production, use a ",[17,489,490],{},"permanent System User token"," (section 5.2 below shows how to verify that it really is permanent), not a temporary token that expires after 24 hours. Otherwise the subscription succeeds now and \"mysteriously\" stops working two days later.",[82,493],{},[34,495,497],{"id":496},"_5-no-guessing-a-layered-debugging-method","5. No guessing: a layered debugging method",[13,499,500,501,504],{},"\"Check subscribed_apps first\" is the conclusion. But if you want to actually locate the problem rather than get lucky, I recommend walking through the path below: ",[17,502,503],{},"work in layers, and verify facts with tools",". Each layer verifies exactly one thing, and each step narrows the search. It applies to any \"third-party webhook isn't calling me back\" problem.",[303,506,508],{"id":507},"_51-layer-one-prove-your-app-and-reverse-proxy-are-fine-one-get-locally-one-against-the-public-url","5.1 Layer one: prove your app and reverse proxy are fine (one GET locally, one against the public URL)",[13,510,511,512,476,514,517,518,521,522,528],{},"WhatsApp's webhook verification is a GET request carrying ",[25,513,134],{},[25,515,516],{},"hub.verify_token"," and ",[25,519,520],{},"hub.challenge",", and it requires you to ",[17,523,524,525,527],{},"echo ",[25,526,520],{}," back unchanged",". Hit it locally first:",[201,530,532],{"className":389,"code":531,"language":391,"meta":206,"style":206},"curl \"http:\u002F\u002F127.0.0.1:8000\u002Fwebhooks\u002Fwhatsapp?hub.mode=subscribe&hub.verify_token=\u003CYOUR_VERIFY_TOKEN>&hub.challenge=test123\"\n# Expected output: test123\n",[25,533,534,541],{"__ignoreMap":206},[210,535,536,538],{"class":212,"line":213},[210,537,399],{"class":398},[210,539,540],{"class":406}," \"http:\u002F\u002F127.0.0.1:8000\u002Fwebhooks\u002Fwhatsapp?hub.mode=subscribe&hub.verify_token=\u003CYOUR_VERIFY_TOKEN>&hub.challenge=test123\"\n",[210,542,543],{"class":212,"line":219},[210,544,546],{"class":545},"sCsY4","# Expected output: test123\n",[13,548,549,550,553,554,557,558,560],{},"Then send the same request to your ",[17,551,552],{},"public domain",". If both echo the ",[25,555,556],{},"challenge",", you have proven that your application logic, your reverse proxy and your ",[25,559,144],{}," are all correct. The matching server-side implementation, using FastAPI as an example:",[201,562,566],{"className":563,"code":564,"language":565,"meta":206,"style":206},"language-py shiki shiki-themes github-light github-dark github-dark","@router.get(\"\u002Fwebhooks\u002Fwhatsapp\")\nasync def verify_webhook(request: Request):\n    mode = request.query_params.get(\"hub.mode\")\n    token = request.query_params.get(\"hub.verify_token\")\n    challenge = request.query_params.get(\"hub.challenge\")\n    if mode == \"subscribe\" and token == EXPECTED_VERIFY_TOKEN:\n        return Response(content=challenge or \"\", media_type=\"text\u002Fplain\")\n    return Response(status_code=403)\n","py",[25,567,568,573,578,583,588,593,598,603],{"__ignoreMap":206},[210,569,570],{"class":212,"line":213},[210,571,572],{},"@router.get(\"\u002Fwebhooks\u002Fwhatsapp\")\n",[210,574,575],{"class":212,"line":219},[210,576,577],{},"async def verify_webhook(request: Request):\n",[210,579,580],{"class":212,"line":225},[210,581,582],{},"    mode = request.query_params.get(\"hub.mode\")\n",[210,584,585],{"class":212,"line":231},[210,586,587],{},"    token = request.query_params.get(\"hub.verify_token\")\n",[210,589,590],{"class":212,"line":237},[210,591,592],{},"    challenge = request.query_params.get(\"hub.challenge\")\n",[210,594,595],{"class":212,"line":243},[210,596,597],{},"    if mode == \"subscribe\" and token == EXPECTED_VERIFY_TOKEN:\n",[210,599,600],{"class":212,"line":249},[210,601,602],{},"        return Response(content=challenge or \"\", media_type=\"text\u002Fplain\")\n",[210,604,605],{"class":212,"line":255},[210,606,607],{},"    return Response(status_code=403)\n",[10,609,610],{},[13,611,612,613,616],{},"Passing this layer is precisely what most easily convinces people that everything is set up. ",[17,614,615],{},"It only proves that the callback URL is valid; it says nothing about whether messages will come in."," Don't be fooled by the words \"subscription verified\".",[303,618,620,621],{"id":619},"_52-layer-two-verify-your-access_token-with-debug_token","5.2 Layer two: verify your access_token with ",[25,622,623],{},"debug_token",[13,625,626,627,629],{},"A lot of \"intermittently can't receive or can't send\" problems are really a token of the wrong type or with the wrong lifetime. The Graph API's ",[25,628,623],{}," tells you at a glance:",[201,631,633],{"className":389,"code":632,"language":391,"meta":206,"style":206},"curl -s \"https:\u002F\u002Fgraph.facebook.com\u002Fdebug_token?input_token=\u003CACCESS_TOKEN>&access_token=\u003CAPP_ID>|\u003CAPP_SECRET>\"\n",[25,634,635],{"__ignoreMap":206},[210,636,637,639,641],{"class":212,"line":213},[210,638,399],{"class":398},[210,640,403],{"class":402},[210,642,643],{"class":406}," \"https:\u002F\u002Fgraph.facebook.com\u002Fdebug_token?input_token=\u003CACCESS_TOKEN>&access_token=\u003CAPP_ID>|\u003CAPP_SECRET>\"\n",[13,645,646],{},"Look at two fields in the response:",[42,648,649,659],{},[45,650,651,654,655,658],{},[25,652,653],{},"type",": for production it should be ",[25,656,657],{},"SYSTEM_USER"," (a system user token, which can be made permanent).",[45,660,661,664,665,671],{},[25,662,663],{},"expires_at",": ",[17,666,667,670],{},[25,668,669],{},"0"," means it never expires",". If it is a future timestamp, the token will expire, and production will break sooner or later.",[673,674,675],"tip",{},[13,676,677,678,681,682,688],{},"A side benefit: this call uses ",[25,679,680],{},"\u003CAPP_ID>|\u003CAPP_SECRET>"," as the caller's credentials, so ",[17,683,684,685,145],{},"a successful response also proves that your ",[25,686,687],{},"app_secret"," (you need it for signature verification).",[303,690,692],{"id":691},"_53-layer-three-sign-your-own-webhook-post-to-verify-the-code-path","5.3 Layer three: sign your own webhook POST to verify the code path",[13,694,695,696,699,700,703,704,706,707,710],{},"To confirm that your code would handle a message correctly if one really came in, you can build a POST ",[17,697,698],{},"with a valid signature"," yourself and send it to your local webhook. WhatsApp computes an HMAC-SHA256 over the ",[17,701,702],{},"raw request body"," using ",[25,705,687],{}," and puts it in the ",[25,708,709],{},"X-Hub-Signature-256"," header:",[201,712,714],{"className":563,"code":713,"language":565,"meta":206,"style":206},"import hmac, hashlib\n\nraw_body = open(\"sample_inbound.json\", \"rb\").read()          # a sample inbound payload\nsig = \"sha256=\" + hmac.new(APP_SECRET.encode(), raw_body, hashlib.sha256).hexdigest()\n# Then use curl \u002F httpx to POST raw_body with this signature header to http:\u002F\u002F127.0.0.1:8000\u002Fwebhooks\u002Fwhatsapp\n",[25,715,716,721,727,732,737],{"__ignoreMap":206},[210,717,718],{"class":212,"line":213},[210,719,720],{},"import hmac, hashlib\n",[210,722,723],{"class":212,"line":219},[210,724,726],{"emptyLinePlaceholder":725},true,"\n",[210,728,729],{"class":212,"line":225},[210,730,731],{},"raw_body = open(\"sample_inbound.json\", \"rb\").read()          # a sample inbound payload\n",[210,733,734],{"class":212,"line":231},[210,735,736],{},"sig = \"sha256=\" + hmac.new(APP_SECRET.encode(), raw_body, hashlib.sha256).hexdigest()\n",[210,738,739],{"class":212,"line":237},[210,740,741],{},"# Then use curl \u002F httpx to POST raw_body with this signature header to http:\u002F\u002F127.0.0.1:8000\u002Fwebhooks\u002Fwhatsapp\n",[13,743,744,745,748],{},"The standard way to verify the signature on the server (note the ",[17,746,747],{},"constant-time comparison",", which guards against timing side channels):",[201,750,752],{"className":563,"code":751,"language":565,"meta":206,"style":206},"expected = \"sha256=\" + hmac.new(APP_SECRET.encode(), raw_body, hashlib.sha256).hexdigest()\nif not hmac.compare_digest(request_signature, expected):\n    logger.warning(\"Webhook signature verification failed\")\n    return {\"status\": \"ok\"}        # Note: return 200 even on failure, see section 6\n",[25,753,754,759,764,769],{"__ignoreMap":206},[210,755,756],{"class":212,"line":213},[210,757,758],{},"expected = \"sha256=\" + hmac.new(APP_SECRET.encode(), raw_body, hashlib.sha256).hexdigest()\n",[210,760,761],{"class":212,"line":219},[210,762,763],{},"if not hmac.compare_digest(request_signature, expected):\n",[210,765,766],{"class":212,"line":225},[210,767,768],{},"    logger.warning(\"Webhook signature verification failed\")\n",[210,770,771],{"class":212,"line":231},[210,772,773],{},"    return {\"status\": \"ok\"}        # Note: return 200 even on failure, see section 6\n",[13,775,776,777,780],{},"If this self-signed POST gets your service to parse, process and reply normally, you have proven that ",[17,778,779],{},"the whole code path works",": signature check → parsing → business dispatch.",[782,783,784],"caution",{},[13,785,786,789,790,793,794,797],{},[17,787,788],{},"There is a blind spot here that you must remember",": a self-signed simulated POST ",[17,791,792],{},"bypasses Meta",". It can prove that your code handles a message once it arrives, but it ",[17,795,796],{},"cannot prove that Meta will actually push the message to you",". The former is a problem in your code; the latter is a platform delivery problem, and ③ belongs to the latter.",[303,799,801],{"id":800},"_54-layer-four-a-real-device-test-which-you-cannot-skip","5.4 Layer four: a real-device test, which you cannot skip",[13,803,804,805,808,809,811],{},"Passing the first three layers only shows that the code and configuration on your side are correct. ",[17,806,807],{},"The only thing that verifies real delivery by Meta is sending a message from a real phone and seeing whether the callback arrives."," The missing ③ ",[25,810,27],{}," in this case could only be exposed by a real device, because it is a switch in the platform's delivery stage, and the first three layers (local GET, token check, self-signed POST) all bypass it.",[201,813,817],{"className":814,"code":815,"language":816,"meta":206,"style":206},"language-txt shiki shiki-themes github-light github-dark github-dark","Local GET echoes the challenge       → verifies: app + reverse proxy + verify_token\ndebug_token on the token             → verifies: access_token type\u002Fexpiry + app_secret\nSelf-signed HMAC simulated POST      → verifies: code path (signature → parsing → dispatch)\nReal-device message, watch callback  → verifies: real delivery by Meta (subscribed_apps and other platform state) ★ cannot be skipped\n","txt",[25,818,819,824,829,834],{"__ignoreMap":206},[210,820,821],{"class":212,"line":213},[210,822,823],{},"Local GET echoes the challenge       → verifies: app + reverse proxy + verify_token\n",[210,825,826],{"class":212,"line":219},[210,827,828],{},"debug_token on the token             → verifies: access_token type\u002Fexpiry + app_secret\n",[210,830,831],{"class":212,"line":225},[210,832,833],{},"Self-signed HMAC simulated POST      → verifies: code path (signature → parsing → dispatch)\n",[210,835,836],{"class":212,"line":231},[210,837,838],{},"Real-device message, watch callback  → verifies: real delivery by Meta (subscribed_apps and other platform state) ★ cannot be skipped\n",[82,840],{},[34,842,844],{"id":843},"_6-a-few-side-traps-worth-clearing-up","6. A few side traps worth clearing up",[13,846,847],{},"While debugging this kind of problem, it is easy to be led astray by a few things that look related but aren't. Here they are in one place.",[303,849,851],{"id":850},"_61-why-return-200-even-when-signature-verification-fails-read-the-logs-not-the-status-code","6.1 Why return 200 even when signature verification fails? Read the logs, not the status code",[13,853,854,855,858,859,862,863,866,867,870,871,20],{},"Meta ",[17,856,857],{},"retries on any non-2xx response",". If you return 4xx\u002F5xx when signature verification fails, a bug in the verification logic itself will bring on a ",[17,860,861],{},"retry storm",". So the right approach is to ",[17,864,865],{},"return 200 whether verification succeeds or fails",", and to surface the anomaly through ",[17,868,869],{},"logs"," rather than the HTTP status code. That means that while debugging you ",[17,872,873],{},"cannot tell from the status code whether verification passed; you have to check the logs for a \"signature verification failed\" warning",[303,875,877],{"id":876},"_62-the-no-payment-method-configured-warning-is-not-why-you-arent-receiving-messages","6.2 The \"no payment method configured\" warning is not why you aren't receiving messages",[13,879,880,881,884,885,888,889],{},"The Meta console often warns that a missing payment method may limit messaging features, which makes it easy to conclude that messages aren't arriving because no payment method is attached. In fact, ",[17,882,883],{},"replies inside the customer service window (within 24 hours of a user-initiated message) are free service messages and need no payment method."," A bot that only responds to users normally works entirely inside this window. A payment method is only needed for ",[17,886,887],{},"proactive pushes, template messages, or volume beyond the free tier",". ",[17,890,891],{},"What actually blocks inbound messages is ③, not payment.",[673,893,894],{},[13,895,896,897,900],{},"The lesson: the most prominent warning on a platform is not necessarily what is blocking you right now. Locate the problem from the ",[17,898,899],{},"symptoms"," (logs, real-device behavior) instead of following the most eye-catching notice to a conclusion.",[303,902,904,905,908],{"id":903},"_63-number-pending-review-or-not-registered-use-the-cloud-api-register-and-it-isnt-a-payment-problem-either","6.3 Number \"pending review\" or \"not registered\": use the Cloud API ",[25,906,907],{},"\u002Fregister",", and it isn't a payment problem either",[13,910,911,912,915],{},"If your number shows as \"not registered\" on ",[25,913,914],{},"wa.me",", or stays \"pending review\", the root cause is usually that it never went through Cloud API number registration:",[201,917,919],{"className":389,"code":918,"language":391,"meta":206,"style":206},"curl -s -X POST \"https:\u002F\u002Fgraph.facebook.com\u002Fv17.0\u002F\u003CPHONE_NUMBER_ID>\u002Fregister\" \\\n  -H \"Authorization: Bearer \u003CACCESS_TOKEN>\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"messaging_product\": \"whatsapp\", \"pin\": \"\u003CYOUR_6_DIGIT_PIN>\"}'\n",[25,920,921,936,945,954],{"__ignoreMap":206},[210,922,923,925,927,929,931,934],{"class":212,"line":213},[210,924,399],{"class":398},[210,926,403],{"class":402},[210,928,452],{"class":402},[210,930,455],{"class":406},[210,932,933],{"class":406}," \"https:\u002F\u002Fgraph.facebook.com\u002Fv17.0\u002F\u003CPHONE_NUMBER_ID>\u002Fregister\"",[210,935,410],{"class":402},[210,937,938,940,943],{"class":212,"line":219},[210,939,415],{"class":402},[210,941,942],{"class":406}," \"Authorization: Bearer \u003CACCESS_TOKEN>\"",[210,944,410],{"class":402},[210,946,947,949,952],{"class":212,"line":225},[210,948,415],{"class":402},[210,950,951],{"class":406}," \"Content-Type: application\u002Fjson\"",[210,953,410],{"class":402},[210,955,956,959],{"class":212,"line":231},[210,957,958],{"class":402},"  -d",[210,960,961],{"class":406}," '{\"messaging_product\": \"whatsapp\", \"pin\": \"\u003CYOUR_6_DIGIT_PIN>\"}'\n",[13,963,964,965,968,969,972],{},"This ",[25,966,967],{},"pin"," is the number's two-step verification PIN. ",[17,970,971],{},"You set it yourself, and you must record it somewhere safe",": you will need it when changing devices, migrating, or re-registering.",[303,974,976],{"id":975},"_64-display-name-review-avoid-internal-or-technical-words","6.4 Display name review: avoid internal or technical words",[13,978,979,980,476,983,986,987,990,991,994],{},"When you submit the number's Display Name for review, names containing internal terms, technical terms, or overly generic words (such as ",[25,981,982],{},"Prod",[25,984,985],{},"Test"," or ",[25,988,989],{},"AI Bot",") tend to be rejected. ",[17,992,993],{},"A real, properly formed brand name"," usually passes quickly.",[303,996,998],{"id":997},"_65-the-webhook-must-return-200-within-5-seconds","6.5 The webhook must return 200 within 5 seconds",[13,1000,1001,1002,1005,1006,1009],{},"Meta requires the webhook to ",[17,1003,1004],{},"respond with 200 within 5 seconds","; otherwise it counts as a failure and is retried. So ",[17,1007,1008],{},"don't do slow work synchronously in the webhook"," (calling an LLM, querying the database, sending messages). The right pattern is to return 200 as soon as the payload is parsed and hand the slow work to a background task:",[201,1011,1013],{"className":563,"code":1012,"language":565,"meta":206,"style":206},"@router.post(\"\u002Fwebhooks\u002Fwhatsapp\")\nasync def webhook(request: Request):\n    body = await request.body()\n    # ... signature verification ...\n    payload = parse(body)\n    for msg in extract_messages(payload):\n        # Idempotent dedup: Meta may redeliver the same message_id\n        if already_processed(msg.id):\n            continue\n        mark_processed(msg.id, ttl=60)\n        asyncio.create_task(handle_message(msg))   # all slow work is async\n    return {\"status\": \"ok\"}                          # 200 immediately\n",[25,1014,1015,1020,1025,1030,1035,1040,1045,1050,1055,1060,1066,1072],{"__ignoreMap":206},[210,1016,1017],{"class":212,"line":213},[210,1018,1019],{},"@router.post(\"\u002Fwebhooks\u002Fwhatsapp\")\n",[210,1021,1022],{"class":212,"line":219},[210,1023,1024],{},"async def webhook(request: Request):\n",[210,1026,1027],{"class":212,"line":225},[210,1028,1029],{},"    body = await request.body()\n",[210,1031,1032],{"class":212,"line":231},[210,1033,1034],{},"    # ... signature verification ...\n",[210,1036,1037],{"class":212,"line":237},[210,1038,1039],{},"    payload = parse(body)\n",[210,1041,1042],{"class":212,"line":243},[210,1043,1044],{},"    for msg in extract_messages(payload):\n",[210,1046,1047],{"class":212,"line":249},[210,1048,1049],{},"        # Idempotent dedup: Meta may redeliver the same message_id\n",[210,1051,1052],{"class":212,"line":255},[210,1053,1054],{},"        if already_processed(msg.id):\n",[210,1056,1057],{"class":212,"line":261},[210,1058,1059],{},"            continue\n",[210,1061,1063],{"class":212,"line":1062},10,[210,1064,1065],{},"        mark_processed(msg.id, ttl=60)\n",[210,1067,1069],{"class":212,"line":1068},11,[210,1070,1071],{},"        asyncio.create_task(handle_message(msg))   # all slow work is async\n",[210,1073,1075],{"class":212,"line":1074},12,[210,1076,1077],{},"    return {\"status\": \"ok\"}                          # 200 immediately\n",[82,1079],{},[34,1081,1083],{"id":1082},"_7-going-further-resolving-the-tenant-from-the-webhook-payload-in-a-multi-tenant-setup","7. Going further: resolving the tenant from the webhook payload in a multi-tenant setup",[13,1085,1086,1087,1090],{},"Once messages are flowing, a multi-tenant system immediately hits the next question: ",[17,1088,1089],{},"which tenant does this message belong to?"," In my case I was adding WhatsApp to a multi-channel conversational assistant that already supported other IM channels, with one number serving one tenant and credentials isolated per tenant. That is when I noticed that, under the same \"channel\" abstraction, different channels resolve the tenant in different ways:",[96,1092,1093,1110],{},[99,1094,1095],{},[102,1096,1097,1100,1107],{},[105,1098,1099],{},"Channel",[105,1101,1102,1103,1106],{},"How the tenant (",[25,1104,1105],{},"tenant_id",") is determined",[105,1108,1109],{},"Needs a stored mapping?",[118,1111,1112,1127,1138],{},[102,1113,1114,1117,1124],{},[123,1115,1116],{},"WhatsApp (this post)",[123,1118,1119,1120,1123],{},"Look up the tenant config table by ",[25,1121,1122],{},"phone_number_id",", cache the result for 24 hours",[123,1125,1126],{},"Yes",[102,1128,1129,1132,1135],{},[123,1130,1131],{},"Other IM channel A",[123,1133,1134],{},"Taken dynamically from the account's login session",[123,1136,1137],{},"No",[102,1139,1140,1143,1146],{},[123,1141,1142],{},"Other IM channel B",[123,1144,1145],{},"Injected directly in the webhook URL path",[123,1147,1148],{},"No (the URL carries it)",[13,1150,1151],{},"Why the difference? It comes down to whether the inbound payload lets you locate the tenant directly:",[42,1153,1154,1168,1171],{},[45,1155,1156,1157,1159,1160,1163,1164,1167],{},"WhatsApp is one number per tenant, and the payload only carries ",[25,1158,1122],{}," (in ",[25,1161,1162],{},"value.metadata","), so you have to use it for a ",[17,1165,1166],{},"reverse lookup"," against a \"number → tenant\" mapping.",[45,1169,1170],{},"Some channels serve several tenants from a single account, and the tenant travels with the login session.",[45,1172,1173],{},"Some channels give each tenant its own webhook URL containing an ID, so the path itself is the answer.",[13,1175,1176],{},"None of the three is better than the others; it depends on what the platform puts in the payload. But the reverse lookup is the only one that requires you to maintain mapping data yourself, which adds two things to watch for around writes and caching.",[303,1178,1180],{"id":1179},"_71-writes-pre-check-first-then-a-rollback-guarded-update","7.1 Writes: pre-check first, then a rollback-guarded update",[13,1182,1183,1184,1186,1187,1190],{},"Tenant-level credentials (",[25,1185,1122],{}," + ",[25,1188,1189],{},"access_token",") live in the database, not in code and not in the repository. When writing credentials for a tenant, I do it in two steps:",[1192,1193,1194,1203],"ol",{},[45,1195,1196,1202],{},[17,1197,1198,1199],{},"Pre-check with a ",[25,1200,1201],{},"SELECT",": confirm the number is not already used by another tenant; the expected result is empty. One number per tenant is the premise the reverse lookup rests on, and once the mapping is duplicated, messages get routed to the wrong tenant.",[45,1204,1205,1211,1212,1215],{},[17,1206,1207,1208],{},"A rollback-guarded ",[25,1209,1210],{},"UPDATE",": run the update inside a transaction and ",[17,1213,1214],{},"commit only if exactly one row was affected","; otherwise roll back. With a wrong condition, zero affected rows means nothing changed and several affected rows is an incident, and neither should be committed.",[303,1217,1219],{"id":1218},"_72-caching-clear-it-after-changing-the-database","7.2 Caching: clear it after changing the database",[13,1221,1222,1223,1226,1227,1230],{},"The ",[25,1224,1225],{},"phone_number_id → tenant_id"," lookup result is cached for 24 hours on a hit, so that not every message queries the database. The cost is that ",[17,1228,1229],{},"if you change the credentials in the database without clearing the cache, the new credentials can take up to 24 hours to take effect."," What you see is \"the database is clearly correct, but production still uses the old value\", which is easy to mistake for one of the platform-side problems above. So treat the database change and clearing the matching cache key as two steps of a single operation, and put them on the same runbook.",[82,1232],{},[34,1234,1236],{"id":1235},"_8-summary-a-debugging-checklist","8. Summary: a debugging checklist",[13,1238,1239],{},"When you hit \"the WhatsApp Cloud API webhook verifies but no messages arrive\", go in this order:",[1192,1241,1242,1254,1263,1282,1288,1291,1297],{},[45,1243,1244,1249,1250,1253],{},[17,1245,1246,1247,382],{},"Check ",[25,1248,381],{}," If it is empty, that is the cause; a ",[25,1251,1252],{},"POST"," fixes it immediately. (90% of cases end here.)",[45,1255,1256,1257,1259,1260,1262],{},"Don't assume that it is automatic for test numbers and only production numbers need it. The subscription is a WABA-level relationship; it does not carry across environments, and someone may have configured it for you without recording it. Run ",[25,1258,381],{}," against the production WABA and ",[25,1261,1252],{}," if it is missing.",[45,1264,1265,1266,1268,1269,517,1271,1273,1274,1276,1277,517,1279,1281],{},"Use ",[25,1267,623],{}," to check the ",[25,1270,653],{},[25,1272,663],{}," of your ",[25,1275,1189],{}," (production needs ",[25,1278,657],{},[25,1280,669],{},").",[45,1283,1284,1285,1287],{},"Judge signature verification from the ",[17,1286,869],{},", not the status code, since a failed verification also returns 200.",[45,1289,1290],{},"Don't be sidetracked by the payment method warning. Replies inside the customer service window are free and need no payment method.",[45,1292,1293,1294,1296],{},"For a number that is \"not registered\", use the Cloud API ",[25,1295,907],{}," (and set a PIN).",[45,1298,1299],{},"Never skip the real-device test. It is the only way to verify real delivery by Meta.",[303,1301,1303],{"id":1302},"keep-the-three-subscriptions-straight","Keep the three \"subscriptions\" straight",[96,1305,1306,1318],{},[99,1307,1308],{},[102,1309,1310,1313,1316],{},[105,1311,1312],{},"Subscription",[105,1314,1315],{},"What it verifies",[105,1317,113],{},[118,1319,1320,1333,1347],{},[102,1321,1322,1325,1330],{},[123,1323,1324],{},"① Webhook URL verification",[123,1326,1327,1328],{},"Callback URL reachable + ",[25,1329,144],{},[123,1331,1332],{},"Your GET endpoint",[102,1334,1335,1341,1344],{},[123,1336,1337,1338,1340],{},"② ",[25,1339,158],{}," field subscription",[123,1342,1343],{},"Which events the App wants",[123,1345,1346],{},"Checkbox in the console",[102,1348,1349,1356,1361],{},[123,1350,1351,1352],{},"③ ",[17,1353,1354],{},[25,1355,27],{},[123,1357,1358],{},[17,1359,1360],{},"Routes WABA events to the App",[123,1362,1363],{},[17,1364,1365],{},"Graph API (the one most often missed)",[673,1367,1368],{},[13,1369,1370,1373,1374,20],{},[17,1371,1372],{},"One closing line",": in the WhatsApp Cloud API, \"verified\" only checks the URL, and \"delivered\" only means the message reached the other person's phone. Neither one means the callback will reach your backend. The switch that actually makes messages flow into your service is called ",[25,1375,27],{},[82,1377],{},[34,1379,1381],{"id":1380},"appendix-a-minimal-fastapi-webhook-you-can-run-as-is","Appendix: a minimal FastAPI webhook you can run as-is",[13,1383,1384,1385,1388,1389,1392,1393,1396,1397,1400],{},"Run ",[25,1386,1387],{},"pip install fastapi uvicorn",", then ",[25,1390,1391],{},"uvicorn app:app --port 8000"," to start it. It takes two environment variables: ",[25,1394,1395],{},"WA_VERIFY_TOKEN"," (the string you chose when configuring the webhook in Meta) and ",[25,1398,1399],{},"WA_APP_SECRET"," (the Meta App's App Secret, used for HMAC signature verification). It ties the points above into a runnable skeleton: echo the challenge on GET, verify the signature on POST, deduplicate idempotently, and return 200 within 5 seconds while processing asynchronously.",[201,1402,1404],{"className":563,"code":1403,"language":565,"meta":206,"style":206},"\"\"\"Minimal runnable WhatsApp Cloud API webhook  ·  uvicorn app:app --port 8000\"\"\"\nimport os, hmac, hashlib, asyncio, time, json, logging\nfrom fastapi import FastAPI, Request, Response\n\nlogging.basicConfig(level=logging.INFO)\nlogger = logging.getLogger(\"wa\")\nVERIFY_TOKEN = os.environ.get(\"WA_VERIFY_TOKEN\", \"\")   # chosen when configuring the webhook in Meta\nAPP_SECRET   = os.environ.get(\"WA_APP_SECRET\", \"\")     # Meta App → App Secret\napp = FastAPI()\n\n_seen = {}  # in-memory dedup (use Redis with a 60s expiry in production)\ndef already_processed(msg_id, ttl=60):\n    now = time.time()\n    for k in [k for k, t in _seen.items() if now - t > ttl]:\n        _seen.pop(k, None)\n    if msg_id in _seen:\n        return True\n    _seen[msg_id] = now\n    return False\n\n\n@app.get(\"\u002Fwebhooks\u002Fwhatsapp\")\nasync def verify(request: Request):\n    p = request.query_params\n    if p.get(\"hub.mode\") == \"subscribe\" and p.get(\"hub.verify_token\") == VERIFY_TOKEN:\n        return Response(content=p.get(\"hub.challenge\", \"\"), media_type=\"text\u002Fplain\")\n    return Response(status_code=403)\n\n\n@app.post(\"\u002Fwebhooks\u002Fwhatsapp\")\nasync def receive(request: Request):\n    body = await request.body()\n    if APP_SECRET:  # HMAC check: return 200 even on failure to avoid a retry storm; rely on logs\n        expected = \"sha256=\" + hmac.new(APP_SECRET.encode(), body, hashlib.sha256).hexdigest()\n        if not hmac.compare_digest(request.headers.get(\"X-Hub-Signature-256\", \"\"), expected):\n            logger.warning(\"[WA] HMAC signature verification failed\")\n            return {\"status\": \"ok\"}\n    try:\n        payload = json.loads(body)\n    except Exception as e:\n        logger.error(f\"[WA] failed to parse payload: {e}\")\n        return {\"status\": \"ok\"}\n    for entry in payload.get(\"entry\", []):\n        for change in entry.get(\"changes\", []):\n            value = change.get(\"value\", {})\n            metadata = value.get(\"metadata\", {})            # contains phone_number_id (the basis for multi-tenant routing)\n            for msg in value.get(\"messages\", []) or []:\n                if already_processed(msg[\"id\"]):\n                    continue\n                asyncio.create_task(handle_message(msg, metadata))\n    return {\"status\": \"ok\"}                                  # 200 right away, within 5 seconds\n\n\nasync def handle_message(msg, metadata):\n    \"\"\"Slow business logic (LLM calls \u002F DB queries \u002F replies) goes here, outside the 5s window\"\"\"\n    try:\n        t = msg.get(\"type\")\n        text = msg.get(\"text\", {}).get(\"body\", \"\") if t == \"text\" else f\"\u003C{t}>\"\n        logger.info(f\"[WA] inbound from={msg.get('from')} type={t} text={text!r} \"\n                    f\"pnid={metadata.get('phone_number_id')}\")\n        # TODO: your business logic \u002F reply via the Graph API\n    except Exception:\n        logger.exception(\"[WA] error while handling message\")\n",[25,1405,1406,1411,1416,1421,1425,1430,1435,1440,1445,1450,1454,1459,1464,1470,1476,1482,1488,1494,1500,1506,1511,1516,1522,1528,1534,1540,1546,1551,1556,1561,1567,1573,1578,1584,1590,1596,1602,1608,1614,1620,1626,1632,1638,1644,1650,1656,1662,1668,1674,1680,1686,1692,1697,1702,1708,1714,1719,1725,1731,1737,1743,1749,1755],{"__ignoreMap":206},[210,1407,1408],{"class":212,"line":213},[210,1409,1410],{},"\"\"\"Minimal runnable WhatsApp Cloud API webhook  ·  uvicorn app:app --port 8000\"\"\"\n",[210,1412,1413],{"class":212,"line":219},[210,1414,1415],{},"import os, hmac, hashlib, asyncio, time, json, logging\n",[210,1417,1418],{"class":212,"line":225},[210,1419,1420],{},"from fastapi import FastAPI, Request, Response\n",[210,1422,1423],{"class":212,"line":231},[210,1424,726],{"emptyLinePlaceholder":725},[210,1426,1427],{"class":212,"line":237},[210,1428,1429],{},"logging.basicConfig(level=logging.INFO)\n",[210,1431,1432],{"class":212,"line":243},[210,1433,1434],{},"logger = logging.getLogger(\"wa\")\n",[210,1436,1437],{"class":212,"line":249},[210,1438,1439],{},"VERIFY_TOKEN = os.environ.get(\"WA_VERIFY_TOKEN\", \"\")   # chosen when configuring the webhook in Meta\n",[210,1441,1442],{"class":212,"line":255},[210,1443,1444],{},"APP_SECRET   = os.environ.get(\"WA_APP_SECRET\", \"\")     # Meta App → App Secret\n",[210,1446,1447],{"class":212,"line":261},[210,1448,1449],{},"app = FastAPI()\n",[210,1451,1452],{"class":212,"line":1062},[210,1453,726],{"emptyLinePlaceholder":725},[210,1455,1456],{"class":212,"line":1068},[210,1457,1458],{},"_seen = {}  # in-memory dedup (use Redis with a 60s expiry in production)\n",[210,1460,1461],{"class":212,"line":1074},[210,1462,1463],{},"def already_processed(msg_id, ttl=60):\n",[210,1465,1467],{"class":212,"line":1466},13,[210,1468,1469],{},"    now = time.time()\n",[210,1471,1473],{"class":212,"line":1472},14,[210,1474,1475],{},"    for k in [k for k, t in _seen.items() if now - t > ttl]:\n",[210,1477,1479],{"class":212,"line":1478},15,[210,1480,1481],{},"        _seen.pop(k, None)\n",[210,1483,1485],{"class":212,"line":1484},16,[210,1486,1487],{},"    if msg_id in _seen:\n",[210,1489,1491],{"class":212,"line":1490},17,[210,1492,1493],{},"        return True\n",[210,1495,1497],{"class":212,"line":1496},18,[210,1498,1499],{},"    _seen[msg_id] = now\n",[210,1501,1503],{"class":212,"line":1502},19,[210,1504,1505],{},"    return False\n",[210,1507,1509],{"class":212,"line":1508},20,[210,1510,726],{"emptyLinePlaceholder":725},[210,1512,1514],{"class":212,"line":1513},21,[210,1515,726],{"emptyLinePlaceholder":725},[210,1517,1519],{"class":212,"line":1518},22,[210,1520,1521],{},"@app.get(\"\u002Fwebhooks\u002Fwhatsapp\")\n",[210,1523,1525],{"class":212,"line":1524},23,[210,1526,1527],{},"async def verify(request: Request):\n",[210,1529,1531],{"class":212,"line":1530},24,[210,1532,1533],{},"    p = request.query_params\n",[210,1535,1537],{"class":212,"line":1536},25,[210,1538,1539],{},"    if p.get(\"hub.mode\") == \"subscribe\" and p.get(\"hub.verify_token\") == VERIFY_TOKEN:\n",[210,1541,1543],{"class":212,"line":1542},26,[210,1544,1545],{},"        return Response(content=p.get(\"hub.challenge\", \"\"), media_type=\"text\u002Fplain\")\n",[210,1547,1549],{"class":212,"line":1548},27,[210,1550,607],{},[210,1552,1554],{"class":212,"line":1553},28,[210,1555,726],{"emptyLinePlaceholder":725},[210,1557,1559],{"class":212,"line":1558},29,[210,1560,726],{"emptyLinePlaceholder":725},[210,1562,1564],{"class":212,"line":1563},30,[210,1565,1566],{},"@app.post(\"\u002Fwebhooks\u002Fwhatsapp\")\n",[210,1568,1570],{"class":212,"line":1569},31,[210,1571,1572],{},"async def receive(request: Request):\n",[210,1574,1576],{"class":212,"line":1575},32,[210,1577,1029],{},[210,1579,1581],{"class":212,"line":1580},33,[210,1582,1583],{},"    if APP_SECRET:  # HMAC check: return 200 even on failure to avoid a retry storm; rely on logs\n",[210,1585,1587],{"class":212,"line":1586},34,[210,1588,1589],{},"        expected = \"sha256=\" + hmac.new(APP_SECRET.encode(), body, hashlib.sha256).hexdigest()\n",[210,1591,1593],{"class":212,"line":1592},35,[210,1594,1595],{},"        if not hmac.compare_digest(request.headers.get(\"X-Hub-Signature-256\", \"\"), expected):\n",[210,1597,1599],{"class":212,"line":1598},36,[210,1600,1601],{},"            logger.warning(\"[WA] HMAC signature verification failed\")\n",[210,1603,1605],{"class":212,"line":1604},37,[210,1606,1607],{},"            return {\"status\": \"ok\"}\n",[210,1609,1611],{"class":212,"line":1610},38,[210,1612,1613],{},"    try:\n",[210,1615,1617],{"class":212,"line":1616},39,[210,1618,1619],{},"        payload = json.loads(body)\n",[210,1621,1623],{"class":212,"line":1622},40,[210,1624,1625],{},"    except Exception as e:\n",[210,1627,1629],{"class":212,"line":1628},41,[210,1630,1631],{},"        logger.error(f\"[WA] failed to parse payload: {e}\")\n",[210,1633,1635],{"class":212,"line":1634},42,[210,1636,1637],{},"        return {\"status\": \"ok\"}\n",[210,1639,1641],{"class":212,"line":1640},43,[210,1642,1643],{},"    for entry in payload.get(\"entry\", []):\n",[210,1645,1647],{"class":212,"line":1646},44,[210,1648,1649],{},"        for change in entry.get(\"changes\", []):\n",[210,1651,1653],{"class":212,"line":1652},45,[210,1654,1655],{},"            value = change.get(\"value\", {})\n",[210,1657,1659],{"class":212,"line":1658},46,[210,1660,1661],{},"            metadata = value.get(\"metadata\", {})            # contains phone_number_id (the basis for multi-tenant routing)\n",[210,1663,1665],{"class":212,"line":1664},47,[210,1666,1667],{},"            for msg in value.get(\"messages\", []) or []:\n",[210,1669,1671],{"class":212,"line":1670},48,[210,1672,1673],{},"                if already_processed(msg[\"id\"]):\n",[210,1675,1677],{"class":212,"line":1676},49,[210,1678,1679],{},"                    continue\n",[210,1681,1683],{"class":212,"line":1682},50,[210,1684,1685],{},"                asyncio.create_task(handle_message(msg, metadata))\n",[210,1687,1689],{"class":212,"line":1688},51,[210,1690,1691],{},"    return {\"status\": \"ok\"}                                  # 200 right away, within 5 seconds\n",[210,1693,1695],{"class":212,"line":1694},52,[210,1696,726],{"emptyLinePlaceholder":725},[210,1698,1700],{"class":212,"line":1699},53,[210,1701,726],{"emptyLinePlaceholder":725},[210,1703,1705],{"class":212,"line":1704},54,[210,1706,1707],{},"async def handle_message(msg, metadata):\n",[210,1709,1711],{"class":212,"line":1710},55,[210,1712,1713],{},"    \"\"\"Slow business logic (LLM calls \u002F DB queries \u002F replies) goes here, outside the 5s window\"\"\"\n",[210,1715,1717],{"class":212,"line":1716},56,[210,1718,1613],{},[210,1720,1722],{"class":212,"line":1721},57,[210,1723,1724],{},"        t = msg.get(\"type\")\n",[210,1726,1728],{"class":212,"line":1727},58,[210,1729,1730],{},"        text = msg.get(\"text\", {}).get(\"body\", \"\") if t == \"text\" else f\"\u003C{t}>\"\n",[210,1732,1734],{"class":212,"line":1733},59,[210,1735,1736],{},"        logger.info(f\"[WA] inbound from={msg.get('from')} type={t} text={text!r} \"\n",[210,1738,1740],{"class":212,"line":1739},60,[210,1741,1742],{},"                    f\"pnid={metadata.get('phone_number_id')}\")\n",[210,1744,1746],{"class":212,"line":1745},61,[210,1747,1748],{},"        # TODO: your business logic \u002F reply via the Graph API\n",[210,1750,1752],{"class":212,"line":1751},62,[210,1753,1754],{},"    except Exception:\n",[210,1756,1758],{"class":212,"line":1757},63,[210,1759,1760],{},"        logger.exception(\"[WA] error while handling message\")\n",[10,1762,1763],{},[13,1764,1765,1766,1768,1769,1772],{},"Deduplication here uses an in-memory dict for demonstration; use Redis (with a 60s expiry) in production. The ",[25,1767,1122],{}," in ",[25,1770,1771],{},"metadata"," is the basis for multi-tenant routing: when one number serves one tenant, use it to look up which tenant the message belongs to (see section 7).",[1774,1775,1776],"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 .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":206,"searchDepth":219,"depth":219,"links":1778},[1779,1780,1783,1784,1788,1795,1803,1807,1810],{"id":36,"depth":219,"text":37},{"id":86,"depth":219,"text":87,"children":1781},[1782],{"id":305,"depth":225,"text":306},{"id":318,"depth":219,"text":319},{"id":371,"depth":219,"text":372,"children":1785},[1786,1787],{"id":385,"depth":225,"text":386},{"id":437,"depth":225,"text":438},{"id":496,"depth":219,"text":497,"children":1789},[1790,1791,1793,1794],{"id":507,"depth":225,"text":508},{"id":619,"depth":225,"text":1792},"5.2 Layer two: verify your access_token with debug_token",{"id":691,"depth":225,"text":692},{"id":800,"depth":225,"text":801},{"id":843,"depth":219,"text":844,"children":1796},[1797,1798,1799,1801,1802],{"id":850,"depth":225,"text":851},{"id":876,"depth":225,"text":877},{"id":903,"depth":225,"text":1800},"6.3 Number \"pending review\" or \"not registered\": use the Cloud API \u002Fregister, and it isn't a payment problem either",{"id":975,"depth":225,"text":976},{"id":997,"depth":225,"text":998},{"id":1082,"depth":219,"text":1083,"children":1804},[1805,1806],{"id":1179,"depth":225,"text":1180},{"id":1218,"depth":225,"text":1219},{"id":1235,"depth":219,"text":1236,"children":1808},[1809],{"id":1302,"depth":225,"text":1303},{"id":1380,"depth":219,"text":1381},"2026-06-12","The Meta console says the webhook is verified and the test message shows as delivered, yet the backend never receives a callback. This post untangles three different things in the WhatsApp Cloud API that are all called a subscription, and lays out a layered way to debug without guessing.","md",null,"\u002Farticles\u002Fwhatsapp-webhook-subscriptions.svg",{},"\u002Farticles\u002Fwhatsapp-webhook-subscriptions","15",{"title":5,"description":1812},{"loc":1817},"articles\u002Fwhatsapp-webhook-subscriptions",[1823,1824],"Backend","Debugging","LnMsobj49VI-YV9ApsO2WquzQa2WdOnlr8Ze9J5fLDQ",1795761651990]