Ai knowledge and logicHelpers

set_message_sending_delay

Control how long the AI waits before actually sending its reply in email conversations.

set_message_sending_delay(context: dict, delay_min: int | None) -> dict

Overrides how long the AI waits between composing a reply and actually sending it, for the current conversation. The override persists for the rest of the conversation and takes precedence over your account-level sending delay. It also applies to the reply the AI is generating right now, so you can set it from the same action or condition provider that decides it's needed.

A sending delay gives customers a grace window: if they write again before the delay elapses — adding details, correcting themselves, or sending a follow-up email — the queued reply is discarded and the AI composes a fresh one that takes the new message into account.

Currently only email conversations delay their sending. On other channels the override is stored but has no effect.


Parameters

NameTypeDescription
contextdictThe context object passed to your code
delay_minint or NoneMinutes to wait before sending each reply. 0 sends immediately. Maximum 10080 (7 days). Pass None to clear the override and return to your account default.

Returns

dict{"success": bool, "message": str}

Behavior

  • The override sticks for the whole conversation until it is changed again or cleared with None.
  • It applies to the reply currently being generated, not just future ones.
  • If the customer sends a new message before a queued reply goes out, that reply is discarded and a fresh one is generated instead.
  • Queued replies are not sent if the conversation is handed off to a human in the meantime.
  • Each change is recorded in the conversation timeline, so you can see when and why the delay changed.
  • In test/mock environments (no conversation attached), returns a mock success response without changing anything.

Examples

Give VIP customers instant replies

def execute_action(context):
    if not context.get("customer"):
        return {"success": True, "vip": False}

    customer = shopify_get_customer(context, context["customer"]["email"])

    if customer and "VIP" in (customer.get("tags") or ""):
        set_message_sending_delay(context, 0)
        return {"success": True, "vip": True}

    return {"success": True, "vip": False}

Slow down replies for conversations that need a cooling-off window

def evaluate_conditions(context):
    is_legal_threat = llm_classify_binary(
        "Does the customer threaten legal action or a chargeback?",
        context["conversation"]["messages"][-1]["content"],
        fallback=False,
    )

    if is_legal_threat:
        # Hold replies for an hour so a human can review or the customer can cool off
        set_message_sending_delay(context, 60)

    return {"conditions": {"legal_threat": is_legal_threat}}

On this page