<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad Hayat</title>
    <description>The latest articles on DEV Community by Mohammad Hayat (@hayatnextoria).</description>
    <link>https://dev.to/hayatnextoria</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4237113%2F1e44c1cb-9b1e-41e2-9a18-0883a73afbb5.png</url>
      <title>DEV Community: Mohammad Hayat</title>
      <link>https://dev.to/hayatnextoria</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hayatnextoria"/>
    <language>en</language>
    <item>
      <title>What LinkedIn actually lets you automate in Page comments (and what it doesn't)</title>
      <dc:creator>Mohammad Hayat</dc:creator>
      <pubDate>Mon, 30 Nov 2026 11:07:42 +0000</pubDate>
      <link>https://dev.to/hayatnextoria/what-linkedin-actually-lets-you-automate-in-page-comments-and-what-it-doesnt-21j7</link>
      <guid>https://dev.to/hayatnextoria/what-linkedin-actually-lets-you-automate-in-page-comments-and-what-it-doesnt-21j7</guid>
      <description>&lt;p&gt;If you run a company Page on LinkedIn, comments are the part that slips. A post does well, forty people reply, and by Thursday half of them have no answer. People notice. A comment left hanging on a business Page reads like nobody is home.&lt;/p&gt;

&lt;p&gt;The obvious fix is "automate it". On LinkedIn that word gets people into trouble, so it's worth being precise about what the platform allows before you build or buy anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Personal profiles and company Pages are different worlds
&lt;/h2&gt;

&lt;p&gt;LinkedIn treats the two very differently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Personal profiles.&lt;/strong&gt; LinkedIn's &lt;a href="https://www.linkedin.com/legal/user-agreement" rel="noopener noreferrer"&gt;User Agreement&lt;/a&gt; lists, among the things you agree not to do: "Use bots or other unauthorized automated methods to access the Services, add or download contacts, send or redirect messages, create, comment on, like, share, or re-share posts". Browser extensions that like, comment or reply on your behalf from your personal account are exactly what that clause is about. LinkedIn's API can post a comment for a member, but reading the comments on a member's posts is restricted to select developers, so an ordinary tool can't watch your personal posts for new comments to answer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Company Pages.&lt;/strong&gt; Here there is an official route: the &lt;a href="https://learn.microsoft.com/en-us/linkedin/marketing/community-management/shares/comments-api" rel="noopener noreferrer"&gt;Community Management API&lt;/a&gt;. An app with that access, approved by LinkedIn, can read the comments on your organization's posts and post replies as the organization. That's the only supported way to answer LinkedIn comments with software.&lt;/p&gt;

&lt;p&gt;So the honest answer to "can I auto-reply to LinkedIn comments?" is: on a company Page, yes, through the official API; on your personal profile, almost certainly not with any tool you can sign up for today.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Page access covers, and what it doesn't
&lt;/h2&gt;

&lt;p&gt;With the organization permissions (w_organization_social_feed and r_organization_social_feed), an app used by a Page admin can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;read comments on posts published by your Page&lt;/li&gt;
&lt;li&gt;reply to those comments, and the reply shows as your Page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can't:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;answer comments under posts on your personal profile&lt;/li&gt;
&lt;li&gt;read or send LinkedIn messages (DMs)&lt;/li&gt;
&lt;li&gt;respond to mentions of you elsewhere&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;LinkedIn's Messages API is restricted to approved partners, so if a tool promises "LinkedIn DM automation" for a personal account, it's working outside the API.&lt;/p&gt;

&lt;h2&gt;
  
  
  A workable setup for a small team
&lt;/h2&gt;

&lt;p&gt;Here's an approach that works for a small team.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Sort before you reply.&lt;/strong&gt; Most Page comments fall into a few groups: congratulations and thanks, real questions, possible customers, complaints, and spam. They need different handling. A "thank you, Sara!" can go out quickly. A pricing question or a complaint needs a person.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Write replies that answer the comment in front of you.&lt;/strong&gt; Canned lines ("Thanks for your comment!") under every post are easy to spot, and they make the Page look automated even when it isn't. A reply that picks up one specific word from the comment reads as human because it is responding to something.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Keep approval on at first.&lt;/strong&gt; Whatever drafts the replies, a person, a template or an AI, have someone approve them for the first couple of weeks. You'll quickly see which kinds of comments are safe to send without review (thank-yous, "see you there") and which never are (prices, complaints, anything legal).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Set a "never answer automatically" list.&lt;/strong&gt; Prices, refunds, job applications, anything that mentions a competitor, anything angry. These go to a person every time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Reply in the commenter's language.&lt;/strong&gt; Pages with an international audience get comments in several languages. Answering in the language the comment was written in is a small thing that people remember.&lt;/p&gt;

&lt;h2&gt;
  
  
  Doing it with tools
&lt;/h2&gt;

&lt;p&gt;You can do all of this by hand from the Page admin view, and for a few comments a week that's fine.&lt;/p&gt;

&lt;p&gt;Past that, look for a tool that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;connects through LinkedIn's official Page access (it will ask you to pick which Pages to connect)&lt;/li&gt;
&lt;li&gt;drafts each reply from the comment itself, not from a fixed template&lt;/li&gt;
&lt;li&gt;has an approval queue, with automatic sending only for categories you choose&lt;/li&gt;
&lt;li&gt;leaves personal-profile comments and DMs alone, because the API doesn't allow them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disclosure: I work on PersonaXpand, which does this for LinkedIn Pages alongside other networks: it drafts each Page comment reply in your own voice, and replies wait for your OK by default. The LinkedIn specifics are here if you want to see how it handles the limits: &lt;a href="https://personaxpand.com/features/ai-auto-reply/linkedin" rel="noopener noreferrer"&gt;https://personaxpand.com/features/ai-auto-reply/linkedin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whatever you use, the rule is the same: stay inside the official API, keep a person on anything that matters, and make every reply about the comment it answers.&lt;/p&gt;

</description>
      <category>linkedin</category>
      <category>automation</category>
      <category>api</category>
      <category>socialmedia</category>
    </item>
    <item>
      <title>Instagram Comments Webhook Not Firing? 7 Causes and the Polling Backstop We Run in Production</title>
      <dc:creator>Mohammad Hayat</dc:creator>
      <pubDate>Mon, 16 Nov 2026 05:13:49 +0000</pubDate>
      <link>https://dev.to/hayatnextoria/instagram-comments-webhook-not-firing-7-causes-and-the-polling-backstop-we-run-in-production-3ja6</link>
      <guid>https://dev.to/hayatnextoria/instagram-comments-webhook-not-firing-7-causes-and-the-polling-backstop-we-run-in-production-3ja6</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm Mohammad Hayat, a Sr. AI Engineer at Nextoria, where we build PersonaXpand, a social media tool that replies to comments and DMs. Everything below is how we handle Instagram comments in production. Meta doc links were checked on 13 Nov 2026.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You subscribed to the &lt;code&gt;comments&lt;/code&gt; field. You clicked &lt;strong&gt;Test&lt;/strong&gt; in the App Dashboard and the sample arrived. Then a real person comments on a real post and your endpoint hears nothing.&lt;/p&gt;

&lt;p&gt;Below: the seven causes we'd check, in order, then a polling backstop that catches what webhooks miss, costs about one API call when nothing changed, and shares a dedupe path with the webhook. The code is C# from our ASP.NET Core app, trimmed, with internal names simplified.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check these first: 7 reasons the comments webhook stays silent
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. You're testing from the account that owns the post
&lt;/h3&gt;

&lt;p&gt;Meta's &lt;a href="https://developers.facebook.com/documentation/instagram-platform/self-messaging.md" rel="noopener noreferrer"&gt;Self Messaging docs&lt;/a&gt; (checked 13 Nov 2026) say a comment by the professional account on its own post does generate a &lt;code&gt;comments&lt;/code&gt; webhook, with a &lt;code&gt;self_ig_scoped_id&lt;/code&gt; in &lt;code&gt;from&lt;/code&gt;. The catch is your own code: any auto-reply system needs a guard that drops the account's own comments, or it answers its own replies. Ours does, so an owner-account test looks like a dead webhook. Test from a second account.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The app is subscribed, but the account isn't
&lt;/h3&gt;

&lt;p&gt;There are two layers. The app subscribes to fields in the App Dashboard. Then each connected account has to be enabled with a &lt;code&gt;POST&lt;/code&gt; to its &lt;code&gt;/subscribed_apps&lt;/code&gt; edge, passing &lt;code&gt;subscribed_fields&lt;/code&gt; and that account's token. The &lt;a href="https://developers.facebook.com/documentation/instagram-platform/webhooks/setup" rel="noopener noreferrer"&gt;webhooks setup guide&lt;/a&gt; (checked 13 Nov 2026) lists the host and token per login type: &lt;code&gt;graph.instagram.com&lt;/code&gt; with an Instagram User token for Instagram Login, &lt;code&gt;graph.facebook.com&lt;/code&gt; with a Page token for Facebook Login. The dashboard Test button never touches this second layer, which is why it can pass while real events don't flow.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Your app is in development mode or lacks the right access level
&lt;/h3&gt;

&lt;p&gt;The same setup guide says the app must be &lt;strong&gt;Live&lt;/strong&gt; to receive notifications for app users, and that Advanced Access is required for &lt;code&gt;comments&lt;/code&gt; and &lt;code&gt;live_comments&lt;/code&gt; notifications. The permissions for comments are &lt;code&gt;instagram_business_basic&lt;/code&gt; plus &lt;code&gt;instagram_business_manage_comments&lt;/code&gt; on Instagram Login, and &lt;code&gt;instagram_basic&lt;/code&gt; plus &lt;code&gt;instagram_manage_comments&lt;/code&gt; (and &lt;code&gt;pages_read_engagement&lt;/code&gt;) on Facebook Login, per the &lt;a href="https://developers.facebook.com/documentation/instagram-platform/comment-moderation.md" rel="noopener noreferrer"&gt;Comment Moderation docs&lt;/a&gt; (checked 13 Nov 2026). Note the docs aren't fully consistent: Comment Moderation describes Standard Access for accounts you own or manage. If your own account works and customer accounts don't, access level is the first suspect.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Your signature check rejects every delivery
&lt;/h3&gt;

&lt;p&gt;Meta signs each payload with HMAC-SHA256 and sends it in &lt;code&gt;X-Hub-Signature-256&lt;/code&gt; as &lt;code&gt;sha256=&amp;lt;hex&amp;gt;&lt;/code&gt;, computed with your app's secret (&lt;a href="https://developers.facebook.com/docs/graph-api/webhooks/getting-started" rel="noopener noreferrer"&gt;Graph API webhooks guide&lt;/a&gt;, checked 13 Nov 2026). Two ways this goes wrong:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;You hash a re-serialized body.&lt;/strong&gt; If a framework parses the JSON and you hash the re-serialized object, the bytes differ and no signature ever matches. Hash the raw body exactly as received.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You check the wrong secret.&lt;/strong&gt; We connect Facebook Pages and Instagram (via Instagram Login) through two different Meta apps. Checking a single secret could only ever validate one of them. Our verifier's comment describes the failure well:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Both apps share a verify token, so the GET handshake succeeds either way and&lt;/span&gt;
&lt;span class="c1"&gt;// the subscription looks healthy in the dashboard while every POST is rejected with a 403.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So our controller buffers the raw body first, then tries each configured app secret with a constant-time compare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EnableBuffering&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;rawBody&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StreamReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTF8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;leaveOpen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;rawBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadToEndAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Position&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;SignatureVerifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rawBody&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signatureHeader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;StatusCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also log &lt;em&gt;which&lt;/em&gt; secret matched (the key name, never the value), so a subscription registered under the wrong app shows up in the logs.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. The media owner is private, or the Live has ended
&lt;/h3&gt;

&lt;p&gt;From the setup guide's limitations: the account that owns the media must be public, and private accounts don't receive comment or mention notifications. Live comment notifications stop when the broadcast ends. Album child media also need care: notifications don't include album IDs, so you look up the album from the comment ID.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. The subscription was made under an old field list
&lt;/h3&gt;

&lt;p&gt;The setup guide's limitations say an account receives every field selected for the app. Our code records a different experience: when we added &lt;code&gt;live_comments&lt;/code&gt;, accounts subscribed under the old field list missed those events. Our fix is a small hosted service that re-subscribes every active Instagram Login account at startup with the current field list. The call is idempotent, so running it on every boot is safe. It's one call per account, with a short delay between accounts.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Meta didn't deliver it, and you can't ask again
&lt;/h3&gt;

&lt;p&gt;The setup guide says Meta retries a failed delivery over the next 36 hours, but the &lt;a href="https://developers.facebook.com/documentation/instagram-platform/webhooks" rel="noopener noreferrer"&gt;webhooks overview&lt;/a&gt; (checked 13 Nov 2026) is clear that webhooks don't provide a historical notification store. If an event never reaches you, there's no replay button. You can't fix this one. You can only catch it, which is what the rest of this post is about.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to test a comments webhook properly
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A second account, a fresh comment, and the raw request log
&lt;/h3&gt;

&lt;p&gt;Log every POST before you act on it: timestamp, body size, and whether the signature passed. Then comment from a second, public account. Nothing in the log points upstream (causes 2, 3, 5). Arrived but rejected is cause 4. Accepted but missing in your app means your own filters (cause 1).&lt;/p&gt;

&lt;h3&gt;
  
  
  What a healthy delivery looks like
&lt;/h3&gt;

&lt;p&gt;The shape differs by login type (the &lt;a href="https://developers.facebook.com/documentation/instagram-platform/webhooks/examples.md" rel="noopener noreferrer"&gt;notification examples&lt;/a&gt; show both), so compare against the one for your setup. For Instagram Login, the &lt;code&gt;value&lt;/code&gt; you care about looks like this, trimmed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"field"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"comments"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;comment id&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"from"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;instagram-scoped user id&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;username&amp;gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Is this still available?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"media"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;media id&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"media_product_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;type&amp;gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the comment &lt;code&gt;id&lt;/code&gt;. It's the key that ties everything below together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you still need a backstop when webhooks work
&lt;/h2&gt;

&lt;p&gt;Even with all seven causes ruled out, events go missing: a deploy restarts the app between Meta's POST and your processing, a token refresh lands mid-flight, or Meta doesn't send one. Two things helped.&lt;/p&gt;

&lt;p&gt;First, we persist the raw payload to a durable inbox table and only then return 200. Processing happens in a background service, and the row survives restarts and deploys, which our old fire-and-forget &lt;code&gt;Task.Run&lt;/code&gt; did not.&lt;/p&gt;

&lt;p&gt;Second, we poll. By default each Instagram account gets a sweep every five minutes. The webhook is the fast path; the poll is the safety net.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7r6gcp5y0qc3qgdw571w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7r6gcp5y0qc3qgdw571w.png" alt="Flow diagram: a new Instagram comment goes to the webhook path (webhook POST, signature check on the raw body, durable inbox) and, if missed, is found by the 5-minute polling sweep (list 25 newest media with comments_count, fetch only media whose count changed, max 8 a sweep). Both paths feed one dedupe on (Platform, PlatformEventId), then the reply pipeline." width="800" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The polling backstop: one cheap call when nothing changed
&lt;/h2&gt;

&lt;p&gt;The naive poll lists recent media and then fetches comments for every one of them. Our first version did that, and a comment in our code records what it cost:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This loop used to fire one comments request PER MEDIA, every sweep,&lt;/span&gt;
&lt;span class="c1"&gt;// unconditionally: 25 media = 26 Graph calls a sweep. Measured on ONE account it came to&lt;/span&gt;
&lt;span class="c1"&gt;// 1,150 Instagram calls in a single hour, against the 200/hr budget this codebase states&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was at an older one-minute cadence. A word on the budget: 200 calls per hour is the number we plan against, and it's the Graph API platform formula (200 × users per hour). Most Instagram Platform calls (not messaging, Business Discovery or Hashtag Search) are actually counted under the Business Use Case limit, 4,800 × impressions per rolling 24 hours (&lt;a href="https://developers.facebook.com/docs/graph-api/overview/rate-limiting" rel="noopener noreferrer"&gt;rate limiting docs&lt;/a&gt;, checked 13 Nov 2026). Either way, 1,150 calls an hour for one account was not sustainable.&lt;/p&gt;

&lt;h3&gt;
  
  
  List recent media with comments_count
&lt;/h3&gt;

&lt;p&gt;The media listing can return &lt;code&gt;comments_count&lt;/code&gt; alongside each id at no extra cost, since it's a field on the same call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="na"&gt;GET /{ig-user-id}/media?fields&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;comments_count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;permalink&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Per the &lt;a href="https://developers.facebook.com/docs/instagram-platform/reference/instagram-media" rel="noopener noreferrer"&gt;IG Media reference&lt;/a&gt; (checked 13 Nov 2026), &lt;code&gt;comments_count&lt;/code&gt; includes replies on comments and excludes comments on album child media.&lt;/p&gt;

&lt;h3&gt;
  
  
  Only fetch comments for media whose count changed
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mediaId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;commentsCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;media&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// No count in the payload? Always fetch, so a payload change can't blind the poller.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;commentsCount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HasValue&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryGetValue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CountKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mediaId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;lastSeen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
        &lt;span class="n"&gt;lastSeen&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;commentsCount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mediaId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Count&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// quiet sweep: just the listing call&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In steady state, a sweep is the one listing call and nothing else.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgqjia32ggcrkoalgmd4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgqjia32ggcrkoalgmd4a.png" alt="Before vs after the comments_count gate, for one quiet sweep of 25 media: before, 26 Graph calls (1 listing call plus 25 comments calls); after, 1 call (the listing call only, 25 skipped). Numbers from our code comments." width="800" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cap the fetches per sweep so a cold start can't spike the quota
&lt;/h3&gt;

&lt;p&gt;After a restart the baseline is empty, so every media looks changed. Without a cap that's a 25-call burst per account. We fetch at most 8 per sweep:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;MaxCommentFetchesPerSweep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;toFetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MaxCommentFetchesPerSweep&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let the rotation correct itself
&lt;/h3&gt;

&lt;p&gt;The baseline for a media is written only &lt;em&gt;after&lt;/em&gt; its comments were read successfully:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A failed or cancelled fetch must leave the old baseline in place, otherwise&lt;/span&gt;
&lt;span class="c1"&gt;// the media would be treated as "seen" and its new comments would never be picked up.&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;countById&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mediaId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;fresh&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;fresh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HasValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CountKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mediaId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fresh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromHours&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Media skipped by the cap keep their old baseline, so they still read as changed next sweep and get their turn. No cursor needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where the baseline lives, and why losing it is fine
&lt;/h3&gt;

&lt;p&gt;It's in &lt;code&gt;IMemoryCache&lt;/code&gt; with a 12-hour TTL, not the database. Losing it on restart costs one extra sweep, which the cap already bounds, and it avoids a migration for what is really cache data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Known blind spots
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Delete plus new comment between sweeps.&lt;/strong&gt; The count stays the same, so the gate skips that media. A deletion on its own moves the count and only causes a harmless re-read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Posts older than the scan depth.&lt;/strong&gt; We scan the newest 25 media. A new comment on an older post is invisible to polling. We raised this from 10 because accounts posting a few times a week were losing visibility on posts barely two weeks old. We deliberately don't filter the media list by date: a new comment can land on a months-old post, so the time filter belongs on comment timestamps, not on media.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One pipeline, two sources: dedupe so nothing is answered twice
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Same store, same event id
&lt;/h3&gt;

&lt;p&gt;Webhook events and polled comments both land in one table, keyed on &lt;code&gt;(Platform, PlatformEventId)&lt;/code&gt;, where the event id is the Instagram comment id from either source. The webhook processor checks incoming ids in one batch query per platform, and a unique index is the last guard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DbUpdateException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DbDuplicateKey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsUniqueViolation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Already stored (a poll or another delivery won the race): nothing is lost.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Coalesce duplicate variants inside one payload
&lt;/h3&gt;

&lt;p&gt;Meta sometimes delivers the same item twice in one payload, through two different fields. If you dedupe by "first one wins", you can keep the variant with the empty sender name. We group by event id and keep the variant with the most sender data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;events&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GroupBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Platform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlatformEventId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OrderByDescending&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SenderName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ThenByDescending&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SenderPlatformId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;First&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Skip the account's own comments
&lt;/h3&gt;

&lt;p&gt;Both paths drop comments where the sender is the connected account. On the webhook side the log line says why: &lt;code&gt;Skipping self-authored ... event ... prevents auto-reply loop&lt;/code&gt;. Without it, every reply you post comes back as a new comment to reply to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stop asking for what Meta keeps refusing
&lt;/h2&gt;

&lt;p&gt;A backstop that retries a refusal every five minutes forever burns quota for nothing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Standing refusals: pause and re-check later
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mentions refused with code 10&lt;/strong&gt; (permission not granted, per the &lt;a href="https://developers.facebook.com/docs/graph-api/guides/error-handling" rel="noopener noreferrer"&gt;error handling guide&lt;/a&gt;, checked 13 Nov 2026). Our code comment notes 70 such refusals from two accounts over three days in October. Now we pause mention fetches for that account for 6 hours, and comments and DMs carry on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An Instagram DM conversation that won't load&lt;/strong&gt; (code 100, subcode 33). It kept appearing in the conversation list, so every sweep asked again: 104 failed calls from two conversations in September. We skip it until a new message arrives. Then we found conversations whose &lt;code&gt;updated_time&lt;/code&gt; changed on every sweep, so that skip never matched (58 failed calls a day from one conversation). Now two refusals in a row means a hard skip for 24 hours.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Back off on throttle codes
&lt;/h3&gt;

&lt;p&gt;Codes 4, 17, 32 and 613 are throttling. Graph can return them inside an HTTP 200 body, so check for an &lt;code&gt;error&lt;/code&gt; object even on success. We back off the account for 10 minutes on a failed send and record a short cool-off when a read comes back throttled. The rate limiting docs also list 80002 for the Instagram Business Use Case limit, worth handling alongside the others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Test from a second, public account, never the owner.&lt;/li&gt;
&lt;li&gt;Confirm each account was enabled via &lt;code&gt;POST /subscribed_apps&lt;/code&gt; with the fields you need.&lt;/li&gt;
&lt;li&gt;App is Live, with the comments permission and the access level the docs require.&lt;/li&gt;
&lt;li&gt;Hash the raw request body, and check every app secret that may sign it.&lt;/li&gt;
&lt;li&gt;Log every POST before verification, with the pass or fail result.&lt;/li&gt;
&lt;li&gt;Re-subscribe existing accounts when you add a field.&lt;/li&gt;
&lt;li&gt;Persist the payload, then return 200 and process in the background.&lt;/li&gt;
&lt;li&gt;Poll with a &lt;code&gt;comments_count&lt;/code&gt; gate, a per-sweep cap, and baselines written only after success.&lt;/li&gt;
&lt;li&gt;Dedupe webhook and poll items on the same comment id, with a unique index behind it.&lt;/li&gt;
&lt;li&gt;Pause standing refusals and back off on throttle codes instead of retrying every sweep.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you want to see this running behind a product, it's what powers comment replies in &lt;a href="https://personaxpand.com/blog/auto-reply-to-instagram-comments" rel="noopener noreferrer"&gt;PersonaXpand&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>instagram</category>
      <category>webhooks</category>
      <category>api</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Building a remote MCP server in ASP.NET Core: OAuth, client registration and the TLS bug we didn't expect</title>
      <dc:creator>Mohammad Hayat</dc:creator>
      <pubDate>Wed, 11 Nov 2026 04:12:49 +0000</pubDate>
      <link>https://dev.to/hayatnextoria/building-a-remote-mcp-server-in-aspnet-core-oauth-client-registration-and-the-tls-bug-we-didnt-5g17</link>
      <guid>https://dev.to/hayatnextoria/building-a-remote-mcp-server-in-aspnet-core-oauth-client-registration-and-the-tls-bug-we-didnt-5g17</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I work on PersonaXpand, a social media tool made by Nextoria in Dubai. This post is about how we built its MCP connector, which lets Claude and ChatGPT post, schedule and answer comments on a person's own accounts. The code patterns apply to any remote MCP server.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most MCP tutorials stop at a local server that talks over stdio. That works for a developer's own laptop. It stops working the moment you want a normal person to click "Connect" inside Claude or ChatGPT and have it just work. Then you need a &lt;strong&gt;remote&lt;/strong&gt; server, and a remote server needs &lt;strong&gt;real OAuth&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We built ours inside an existing ASP.NET Core 10 app with the official C# SDK (&lt;code&gt;ModelContextProtocol.AspNetCore&lt;/code&gt;). Here is what we learned, including three things that cost us days.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Run the transport stateless
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddMcpServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ServerInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Implementation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"personaxpand"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"PersonaXpand"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1.0.0"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithHttpTransport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stateless&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithTools&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PersonaXpandTools&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Streamable HTTP can keep a session per client. Don't, unless you need server-to-client streaming. Our app runs on more than one instance behind a load balancer, and a stateful session pinned to one instance breaks the moment the next request lands somewhere else. With &lt;code&gt;Stateless = true&lt;/code&gt;, any instance can answer any call, and every request carries its own bearer token.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Your app is now an OAuth authorization server
&lt;/h2&gt;

&lt;p&gt;The assistant discovers everything from two well-known documents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/.well-known/oauth-protected-resource&lt;/code&gt; on the MCP server says which authorization server to use.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/.well-known/oauth-authorization-server&lt;/code&gt; lists the authorize, token, registration and revocation endpoints.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then it needs a client ID. Nobody pre-registers "Claude on someone's laptop", so the spec gives you two ways to get one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Client Registration (DCR, RFC 7591):&lt;/strong&gt; the client POSTs its name and redirect URIs and gets an ID back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client ID Metadata Documents (CIMD):&lt;/strong&gt; the client ID &lt;em&gt;is&lt;/em&gt; an https URL, and you fetch a JSON document from it that lists the redirect URIs. No registration call at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Support both. Different assistants use different ones, and CIMD is where things are heading because the client's identity is tied to a domain it controls.&lt;/p&gt;

&lt;p&gt;The rest is standard OAuth 2.1 and worth doing properly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PKCE on every authorization code&lt;/strong&gt;, S256 only. Codes live 60 seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Short access tokens (1 hour), rotating refresh tokens (30 days).&lt;/strong&gt; Each refresh returns a new refresh token and retires the old one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Refresh reuse detection with a grace window.&lt;/strong&gt; If a retired refresh token comes back, that is either theft or a client retrying after a network blip. We allow a reuse within 60 seconds of rotation (retries are real and common) and revoke the whole connection after that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Store every secret hashed.&lt;/strong&gt; Codes, access tokens and refresh tokens are looked up by hash. A database leak should not hand out working tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Revocation on password change.&lt;/strong&gt; When the person changes their password, every assistant connection is cut.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Open registration needs a redirect allowlist
&lt;/h2&gt;

&lt;p&gt;This is the one we got wrong at first.&lt;/p&gt;

&lt;p&gt;DCR means &lt;em&gt;anyone&lt;/em&gt; can register a client with &lt;em&gt;any&lt;/em&gt; redirect URI. An attacker can register their own site as the return address, then send a victim a perfectly real consent link on your domain. The victim sees your real login page and a real "Allow" button. If they click it, the authorization code goes to the attacker's site.&lt;/p&gt;

&lt;p&gt;PKCE doesn't save you here, because the attacker started the flow and holds the verifier.&lt;/p&gt;

&lt;p&gt;Our fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nc"&gt;DefaultRedirectHosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"claude.ai"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"claude.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"chatgpt.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"openai.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"vscode.dev"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;IsRedirectHostAllowed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;redirectUri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;Uri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;redirectUri&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;UriKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Absolute&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IsLoopback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;// a code sent here only reaches the person's own machine&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;_config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Mcp:RedirectAllowlist"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// kill switch&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;extra&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetSection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Mcp:ExtraRedirectHosts"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;HostIs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;DefaultRedirectHosts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three details matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Loopback always passes.&lt;/strong&gt; Many desktop clients redirect to &lt;code&gt;http://127.0.0.1:&amp;lt;random port&amp;gt;&lt;/code&gt;. A code sent there can only reach the machine of the person who clicked Allow. Per RFC 8252, match loopback redirects without the port, because the port changes on every run.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New hosts come from config, not code.&lt;/strong&gt; When a new assistant appears, you add its host in app settings without a deploy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep a kill switch.&lt;/strong&gt; If a real assistant gets turned away at 2 a.m., you can switch the list off while you work out its host.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The error message matters too. Ours tells the developer exactly which host was refused and who to email, instead of a bare &lt;code&gt;invalid_redirect_uri&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The consent screen is a security boundary
&lt;/h2&gt;

&lt;p&gt;Say plainly what the assistant will be able to do. Ours separates "read" (see posts, analytics, inbox) from "act" (publish, schedule, send replies), and anything that would send a message on someone's account still asks the person first inside the chat. Assistants are good at following instructions, including ones hidden in a comment someone left on your post. Treat everything that comes from outside the person's own account as data, never as instructions, and say so in your tool descriptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The TLS bug: your server may not be able to fetch the client's document
&lt;/h2&gt;

&lt;p&gt;This one took the longest, because nothing in our code was wrong.&lt;/p&gt;

&lt;p&gt;CIMD means your server makes an outbound HTTPS request to the client's domain to fetch its metadata. One MCP directory's CIMD sign-in kept failing with "This app is not registered". Locally it worked. In production it didn't.&lt;/p&gt;

&lt;p&gt;The production logs showed a &lt;strong&gt;TLS handshake failure&lt;/strong&gt;. We run on Azure App Service on Windows, where outbound TLS goes through SChannel. The other side only accepted &lt;strong&gt;TLS 1.3 with the X25519 key exchange&lt;/strong&gt;, and refused TLS 1.2 and the P-256/P-384 curves. Our Windows host and their server simply had no handshake in common.&lt;/p&gt;

&lt;p&gt;What we learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Log the exception type on every outbound metadata fetch.&lt;/strong&gt; "Could not read client metadata" hides a TLS failure behind what looks like a bad client ID.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test CIMD from the same OS and host as production.&lt;/strong&gt; Your laptop's TLS stack is not your server's.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tell the other side.&lt;/strong&gt; We emailed them the handshake details. They added TLS 1.2 with P-256 the next day, which fixed it for every Windows-hosted server, not only ours.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Smaller things that saved us
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Filter tools per client.&lt;/strong&gt; Some tools only make sense in one assistant (we hide image generation from Claude to follow its directory rules). &lt;code&gt;AddListToolsFilter&lt;/code&gt; and &lt;code&gt;AddCallToolFilter&lt;/code&gt; let one server present different tool lists by client.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Serialize destructive calls per account.&lt;/strong&gt; An assistant may fire 20 deletes in parallel. If you have a "confirm before many deletes" rule that counts recent deletes, all 20 see a count of zero. A per-account distributed lock around destructive tools fixes it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch your clock.&lt;/strong&gt; OAuth and signed-request flows fail with confusing "invalid grant" errors when a machine's clock is off. We found a dev box four hours off UTC this way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Publish to the official MCP Registry.&lt;/strong&gt; Directories and clients increasingly read from it. Ownership is proven with a DNS TXT record on your domain, so keep that record.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it or read the docs
&lt;/h2&gt;

&lt;p&gt;The server is live at &lt;code&gt;https://personaxpand.com/mcp&lt;/code&gt;. The listing files and docs are on &lt;a href="https://github.com/Nextoria-Information-Technology-LLC/personaxpand-mcp" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, and setup steps are on our &lt;a href="https://personaxpand.com/mcp" rel="noopener noreferrer"&gt;MCP page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you are building a remote MCP server in .NET and hit one of these, ask in the comments. Happy to share more detail.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>dotnet</category>
      <category>oauth</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
