DEV Community

Meera Sen
Meera Sen

Posted on

Model an Instagram Comment-to-DM Flow as a Small State Machine

An Instagram comment-to-DM workflow is easier to reason about when it is modeled as a small state machine instead of a chain of marketing messages.

States

  • comment_received
  • promise_delivered
  • context_provided
  • question_asked
  • human_reply
  • closed

The first transition must deliver the value named in the post. Qualification or lead capture should happen only after promise_delivered.

Events and guards

Normalize realistic input: case, whitespace, surrounding words, emoji and duplicate comments. Guard against re-entry so a second comment does not restart an unwanted sequence.

A minimal transition table:

Current state Event Next state
comment_received valid keyword promise_delivered
promise_delivered link sent context_provided
context_provided optional question sent question_asked
any active state human reply human_reply
any active state opt-out or invalid route closed

Acceptance tests

  1. Exact keyword.
  2. Lowercase keyword in a sentence.
  3. Duplicate comment.
  4. Destination opened on mobile.
  5. Human reply before the optional question.
  6. Contact source stored correctly.

DMComments supports triggers from comments, story replies, live comments and inbound DMs through Meta’s official Instagram API. Use its preview step to verify each transition before enabling the workflow.

A short automation feels human when every transition respects the event that caused it.

Top comments (0)