# चैट को अपने बॉट से किसी व्यक्ति को सौंपें और वापस लें

> पहचानें कि WhatsApp ग्राहक किसी व्यक्ति से बात करना चाहता है, सारांश के साथ चैट अपनी टीम को सौंपें, उसे असाइन करें, जब तक कोई व्यक्ति जवाब दे रहा है तब तक हर बॉट और AI जवाब को चुप रखें, और सुलझ जाने पर उसे बॉट को लौटा दें।

बॉट सरल सवालों पर तेज़ होता है। कुछ चैट को किसी व्यक्ति की ज़रूरत होती है: रिफ़ंड, शिकायत, गड़बड़ हुआ ऑर्डर, या ऐसा ग्राहक जो बस लिख देता है "can I talk to someone?"।

इस गाइड में आपका बॉट ऐसी चैट अपनी टीम को सौंपता है, और टीम का काम पूरा होने पर उसे वापस ले लेता है।

**ग्राहक को क्या दिखता है:** वे किसी व्यक्ति के लिए कहते हैं, और बॉट जवाब देता है "Thanks! A person from our team will answer you here soon." उसके बाद केवल आपकी टीम जवाब देती है, उसी WhatsApp चैट में। बीच में कोई बॉट जवाब या AI जवाब नहीं आता।

**आपको क्या दिखता है:** app2email Inbox में वह चैट, आपकी टीम के एक व्यक्ति को असाइन की हुई, एक आंतरिक नोट के साथ जो बताता है कि बॉट ने उसे क्यों सौंपा और ग्राहक ने क्या पूछा। हर बदलाव के लिए आपके webhook को एक इवेंट मिलता है: चैट का owner कौन है, वह किसे असाइन है, और वह कब सुलझी।

## यह कैसे काम करता है

हर बातचीत (हर संपर्क की एक) का एक **owner** होता है। owner बताता है कि अभी उस संपर्क को कौन जवाब देता है। आप इसे एक कॉल से सेट करते हैं, `PUT /conversations/{contact}/owner`:

| `owner` | मतलब | क्या होता है |
| --- | --- | --- |
| `""` (खाली) | सामान्य रूटिंग | नंबर का ऑटो रिप्लाई, चैट ऑटोमेशन, AI जवाब और A2A / OpenClaw एजेंट वैसे काम करते हैं जैसा आपने सेट किया है। |
| `agent` | कोई ऑटोमेशन इसका owner है | बाकी सबके लिए एक निशान: "कोई ऑटोमेशन इस संपर्क को संभाल रहा है"। AI जवाब चुप रहते हैं, क्योंकि वे केवल उसी बातचीत का जवाब देते हैं जिसका कोई owner नहीं है। |
| `human` | कोई व्यक्ति owner है | app2email का ऑटो रिप्लाई और A2A / OpenClaw एजेंट संपर्क को छोड़ देते हैं, और AI जवाब भी। आपकी टीम जवाब देती है। |
| `paused` | स्वचालित जवाब रोके गए हैं | ऑटो रिप्लाई, A2A / OpenClaw एजेंट और AI जवाबों के लिए `human` जैसा ही। |

owner कोई भी हो, ईमेल फ़ॉरवर्डिंग जारी रहती है, इसलिए जिन लोगों को WhatsApp मैसेज ईमेल से मिलते हैं उन्हें वे मिलते रहते हैं।

इस गाइड में हैंडओवर ऐसे काम करता है:

1. कोई ग्राहक आपके नंबर पर लिखता है। आपके webhook को `message.received` मिलता है।
2. आपका बॉट बातचीत पढ़ता है (`GET /conversations/{contact}`)। अगर कोई व्यक्ति पहले से उसका owner है, तो बॉट कुछ नहीं करता।
3. अगर ग्राहक किसी व्यक्ति को मांगता है, तो बॉट `reason` और `summary` के साथ owner को `human` सेट करता है, ग्राहक को बताता है कि कोई व्यक्ति जवाब देगा, चैट को टीम के किसी व्यक्ति को असाइन करता है और एक आंतरिक नोट जोड़ता है।
4. कोई व्यक्ति Inbox से, ईमेल से या API से जवाब देता है।
5. जब टीम चैट को सुलझा हुआ चिह्नित करती है, तो बॉट owner को वापस `""` कर देता है और अगले मैसेज का फिर से जवाब देता है। `until_minutes` भी तय समय के बाद चैट अपने आप लौटा सकता है।

<Note>
आपके webhook को नंबर का हर इवेंट मिलता रहता है, उस चैट का `message.received` भी जिसका owner कोई व्यक्ति है। app2email का अपना ऑटो रिप्लाई, A2A / OpenClaw एजेंट और AI जवाब owner को खुद जांचते हैं। **आपके अपने बॉट को भी इसे जांचना होगा**, हर जवाब से पहले।
</Note>

## आपको क्या चाहिए

- **app2email से जुड़ा एक WhatsApp नंबर**, सशुल्क प्लान पर और चालू। प्लान के बिना हर कॉल पर 403 `plan_not_allowed` आता है; रुकी हुई सेवा पर 403 `service_not_live`। देखें [शुरू करना](https://www.app2email.com/docs/onboarding)।
- **webhook पर मैसेज पाने वाला एक बॉट।** अगर आपके पास अभी नहीं है, तो [API से WhatsApp चैटबॉट बनाएं](/guides/how-to-whatsapp-chatbot) एक बॉट सेट करता है (टनल, `POST /webhooks`, signing secret)। यह गाइड उसमें हैंडओवर जोड़ती है।
- **एक API key**, [API key पेज](https://www.app2email.com/dashboard/apikey) से, इन scopes के साथ:

| Scope | यहां यह किसलिए है |
| --- | --- |
| `messages:send` | owner सेट करना (`PUT /conversations/{contact}/owner`), चैट असाइन करना (`PUT /conversations/{contact}/assignee`), उसे सुलझा हुआ चिह्नित करना (`PUT /conversations/{contact}/status`), नोट जोड़ना (`POST /conversations/{contact}/notes`), ग्राहक को मैसेज भेजना (`POST /messages`) |
| `messages:read` | एक बातचीत पढ़ना (`GET /conversations/{contact}`), बातचीतों की सूची, टीम (`GET /team/members`) और नोट |
| `webhooks:manage` | webhook को एक बार रजिस्टर करना (`POST /webhooks`), या उसे API key पेज पर जोड़ना |

- **असाइनमेंट, नोट और सुलझा / खुला के लिए:** टीम inbox। यह Trial और Professional प्लान के साथ आता है। दूसरे प्लान पर ये कॉल 403 `team_inbox_not_in_plan` देते हैं; owner खुद हर सशुल्क प्लान पर काम करता है।

<Tip>
**आज़माना।** **तुरंत मिलने वाला sandbox** बिना अकाउंट के चलता है: `POST https://api.app2email.com/v1/account/sandbox` (बिना key, बिना body) या Management MCP सर्वर `https://api.app2email.com/mcp/manage` का `create_sandbox` टूल डेमो नंबर `12025550100` की key देता है। इसका नकली ग्राहक `12025550105` किसी व्यक्ति को मांगता है, इसलिए आप पहचान को जांच सकते हैं। तुरंत मिलने वाले sandbox में `PUT /conversations/{contact}/owner`, `GET /conversations`, `POST /messages` और `GET /events` हैं (इवेंट वहीं पढ़ें, उसमें webhooks नहीं हैं)। टीम वाले कॉल (members, assignee, status, notes) वहां 403 `not_in_instant_sandbox` देते हैं। विवरण: [Sandbox](/api/sandbox)।
</Tip>

<Warning>
**अपने नंबर पर sandbox key** WhatsApp को कुछ नहीं भेजती, लेकिन owner, assignee, status और नोट आपकी बातचीतों में **असली बदलाव** हैं, sandbox key के साथ भी। इन कॉल को अपने ही किसी संपर्क पर आज़माएं, जैसे आपका अपना फ़ोन।
</Warning>

## चरण दर चरण सौंपना

हर रिक्वेस्ट में `YOUR_NUMBER` वह WhatsApp नंबर है जिससे आप भेजते हैं: पहले देश कोड, सिर्फ़ अंक। संपर्क ग्राहक का नंबर (पहले देश कोड) या उसका business-scoped user id (जैसे `AU.1234567890123456`) है, यानी इवेंट का `from` या `from_user_id`।

<Steps>
  <Step title="देखें कि चैट का owner कौन है">
    `GET /conversations/{contact}` (scope `messages:read`) आपको owner बताता है, कि अभी free-form जवाब भेजा जा सकता है या नहीं, और कि ईमेल जवाब इंतज़ार में हैं या नहीं। इसे अपने बॉट के हर जवाब से पहले कॉल करें।

    <CodeGroup>

    ```bash cURL
    curl https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678 \
      -H "Authorization: Bearer YOUR_API_KEY"
    ```

    ```javascript Node.js
    const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678", {
      headers: { Authorization: `Bearer ${process.env.API_KEY}` },
    });
    const conv = await res.json();
    console.log(conv.owner, conv.window_open);
    ```

    ```python Python
    import os, requests

    res = requests.get("https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678",
                       headers={"Authorization": f"Bearer {os.environ['API_KEY']}"}, timeout=10)
    conv = res.json()
    print(conv.get("owner"), conv.get("window_open"))
    ```

    </CodeGroup>

    **जवाब में आपको क्या मिलता है** (ऐसी चैट जिसका owner कोई व्यक्ति है):

    ```json
    {
      "success": true,
      "request_id": "c9slm",
      "contact": "61412345678",
      "identity_type": "phone",
      "phone": "61412345678",
      "name": "John",
      "window_state": "open",
      "window_open": true,
      "window_closes_at": "2026-11-22T01:05:44Z",
      "last_inbound_at": "2026-11-21T01:20:44Z",
      "last_outbound_at": "2026-11-21T01:12:09Z",
      "messages": 12,
      "owner": "human",
      "owner_set_at": "2026-11-21T01:21:00Z",
      "owner_set_by": "api:Support bot",
      "owner_reason": "customer asked for a person",
      "owner_summary": "Wants to move the delivery to Monday.",
      "held_replies": false,
      "conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_..."
    }
    ```

    | फ़ील्ड | यह आपके बॉट को क्या बताता है |
    | --- | --- |
    | `owner` | `""` सामान्य रूटिंग, `agent`, `human` या `paused`। जवाब केवल तब दें जब यह `""` हो (या `agent`, अगर `agent` आपके अपने बॉट का निशान है) |
    | `owner_set_by` | इसे किसने सेट किया, जैसे `api:Support bot` (key का नाम) |
    | `owner_reason`, `owner_summary` | हैंडओवर के साथ क्या दिया गया |
    | `owner_until` | अस्थायी owner कब खत्म होता है। बीता हुआ समय फिर से `""` के बराबर है |
    | `owner_set` | क्या सेट किया गया था, `owner_until` बीत जाने पर भी |
    | `window_state`, `window_open` | `open`: अभी free-form जवाब भेजा जा सकता है। `closed`: केवल मंज़ूर टेम्पलेट |
    | `window_closes_at` | विंडो ठीक कब बंद होती है |
    | `held_replies` | `true`: ईमेल जवाब इंतज़ार में हैं कि संपर्क "Show reply" पर टैप करे, क्योंकि 24 घंटे की विंडो बंद हो चुकी थी |

    जिस फ़ील्ड का कोई मान नहीं होता, वह जवाब से छोड़ दिया जाता है, इसलिए सामान्य रूटिंग वाली चैट में हो सकता है कि कोई `owner_*` फ़ील्ड बिल्कुल न हो। जिस संपर्क ने कभी नहीं लिखा, उस पर 404 `conversation_not_found` आता है।
  </Step>
  <Step title="पहचानें कि ग्राहक किसी व्यक्ति से बात करना चाहता है">
    आपका बॉट यह `message.received` इवेंट से तय करता है। तीन संकेत अच्छे काम करते हैं:

    - टेक्स्ट मैसेज में **शब्द**: "person", "human", "someone", "staff", "manager"।
    - **एक बटन।** "Talk to a person" को अपने id वाले reply बटन के रूप में दें। टैप `type` `interactive` और `interactive.id` के साथ आता है।
    - **आपका बॉट अटक गया है**, जैसे ग्राहक को लगातार दो बार मेन्यू मिला, या उसने ऐसी फ़ोटो या वॉइस नोट भेजा जिसे आपका बॉट नहीं पढ़ सकता।

    reply बटन पर टैप ऐसे आता है:

    ```json
    {
      "id": "evt_Pa3k9m2Lw8Rt5Yp1Zs012",
      "type": "message.received",
      "created": "2026-11-21T01:20:44.000Z",
      "number": "4976659348270",
      "data": {
        "message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
        "from": "61412345678",
        "from_user_id": "AU.1234567890123456",
        "name": "John",
        "type": "interactive",
        "text": "Talk to a person",
        "interactive": {
          "type": "button_reply",
          "id": "person",
          "title": "Talk to a person"
        },
        "conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_SAMPLEk3XbQ9rTzP2mW",
        "timestamp": "2026-11-21T01:20:44.000Z"
      }
    }
    ```

    बटन खुद एक सामान्य interactive मैसेज है, जो 24 घंटे की विंडो के भीतर भेजा जाता है:

    ```json
    {
      "to": "61412345678",
      "type": "interactive",
      "interactive": {
        "type": "button",
        "body": { "text": "What would you like to do?" },
        "action": {
          "buttons": [
            { "type": "reply", "reply": { "id": "track", "title": "Track my order" } },
            { "type": "reply", "reply": { "id": "person", "title": "Talk to a person" } }
          ]
        }
      }
    }
    ```

    अपने बॉट के बजाय AI जवाब (app2email का असिस्टेंट) इस्तेमाल कर रहे हैं? वह इसे खुद पहचानता है और चैट सौंप देता है: देखें [AI जवाब खुद चैट सौंपते हैं](#ai-answers-hand-over-by-themselves)।
  </Step>
  <Step title="चैट किसी व्यक्ति को दें">
    `"owner": "human"` के साथ `PUT /conversations/{contact}/owner` (scope `messages:send`):

    | फ़ील्ड | ज़रूरी | क्या डालें |
    | --- | --- | --- |
    | `owner` | हां | `human`। साथ ही `agent`, `paused`, या सामान्य पर लौटने के लिए `""` |
    | `reason` | नहीं | क्यों, कुछ शब्दों में (200 अक्षर तक), जैसे `customer asked for a person` |
    | `summary` | नहीं | चैट अब तक किस बारे में है, कार्यभार लेने वाले व्यक्ति के लिए (2000 अक्षर तक)। जो लोग WhatsApp मैसेज ईमेल से पढ़ते हैं, उन्हें भी यह मिलता है |
    | `until_minutes` | नहीं | 1 से 43200। इतने मिनट बाद owner अपने आप `""` हो जाता है |

    <CodeGroup>

    ```bash cURL
    curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/owner \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"owner": "human", "reason": "customer asked for a person", "summary": "Wants to move the delivery to Monday.", "until_minutes": 480}'
    ```

    ```javascript Node.js
    const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/owner", {
      method: "PUT",
      headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
      body: JSON.stringify({
        owner: "human",
        reason: "customer asked for a person",
        summary: "Wants to move the delivery to Monday.",
        until_minutes: 480,
      }),
    });
    console.log(res.status, await res.json());
    ```

    ```python Python
    res = requests.put(
        "https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/owner",
        headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
        json={"owner": "human", "reason": "customer asked for a person",
              "summary": "Wants to move the delivery to Monday.", "until_minutes": 480},
        timeout=10,
    )
    print(res.status_code, res.json())
    ```

    </CodeGroup>

    **जवाब में आपको क्या मिलता है** (200): अपडेट की गई बातचीत, चरण 1 जैसे ही फ़ील्ड के साथ।

    ```json
    {
      "success": true,
      "request_id": "own3r",
      "conversation": {
        "contact": "61412345678",
        "identity_type": "phone",
        "phone": "61412345678",
        "name": "John",
        "window_state": "open",
        "window_open": true,
        "window_closes_at": "2026-11-22T01:05:44Z",
        "messages": 12,
        "owner": "human",
        "owner_set": "human",
        "owner_set_at": "2026-11-21T01:21:00Z",
        "owner_set_by": "api:Support bot",
        "owner_reason": "customer asked for a person",
        "owner_summary": "Wants to move the delivery to Monday.",
        "owner_until": "2026-11-21T09:21:00Z",
        "held_replies": false,
        "conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_..."
      }
    }
    ```

    अब से app2email का ऑटो रिप्लाई, A2A / OpenClaw एजेंट और AI जवाब इस संपर्क को छोड़ देते हैं, और नंबर के हर webhook को `conversation.owner_changed` मिलता है। वही owner दोबारा सेट करना हानिरहित है, इसलिए इस कॉल को दोबारा भेजना सुरक्षित है।

    <Tip>
    `until_minutes` को अपने खुलने के समय के अनुसार चुनें। 480 (8 घंटे) के साथ, जिस चैट को किसी ने नहीं उठाया वह अपने आप बॉट के पास लौट जाती है। इसे छोड़ दें तो चैट तब तक आपकी टीम के पास रहती है जब तक कोई उसे वापस न दे।
    </Tip>
  </Step>
  <Step title="ग्राहक को बताएं">
    जब तक 24 घंटे की विंडो खुली है (`window_open` true है, और है, क्योंकि ग्राहक ने अभी लिखा), `POST /messages` से एक छोटा free-form टेक्स्ट भेजें। उसे ग्राहक के `message_id` से बनी `Idempotency-Key` दें, ताकि दोबारा कोशिश पर वह दो बार न जाए।

    <CodeGroup>

    ```bash cURL
    curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/messages \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: handoff-wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=" \
      -d '{"to": "61412345678", "type": "text", "text": {"body": "Thanks! A person from our team will answer you here soon."}}'
    ```

    ```javascript Node.js
    await fetch("https://api.app2email.com/v1/YOUR_NUMBER/messages", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.API_KEY}`,
        "Content-Type": "application/json",
        "Idempotency-Key": `handoff-${messageId}`,
      },
      body: JSON.stringify({
        to: "61412345678",
        type: "text",
        text: { body: "Thanks! A person from our team will answer you here soon." },
      }),
    });
    ```

    ```python Python
    requests.post(
        "https://api.app2email.com/v1/YOUR_NUMBER/messages",
        headers={"Authorization": f"Bearer {os.environ['API_KEY']}", "Idempotency-Key": f"handoff-{message_id}"},
        json={"to": "61412345678", "type": "text",
              "text": {"body": "Thanks! A person from our team will answer you here soon."}},
        timeout=10,
    )
    ```

    </CodeGroup>

    **जवाब में आपको क्या मिलता है** (200):

    ```json
    {
      "success": true,
      "request_id": "kxrkf",
      "message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBI5QTNDQTVCM0Q0Q0Q2RTY3RTgA",
      "status": "accepted",
      "type": "text",
      "from": "4976659348270",
      "to": "61412345678",
      "window_closes_at": "2026-11-22T01:05:44Z",
      "conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_..."
    }
    ```

    विंडो बंद हो गई? तब भेजने पर 422 `outside_24h_window` आता है और ग्राहक तक केवल मंज़ूर टेम्पलेट पहुंच सकता है।
  </Step>
  <Step title="इसे टीम के किसी व्यक्ति को असाइन करें">
    `GET /team/members` (scope `messages:read`) बताता है कि कौन बातचीत ले सकता है: नंबर का owner और वे सदस्य जो जवाब दे सकते हैं (viewers को असाइन नहीं किया जा सकता)।

    ```bash
    curl https://api.app2email.com/v1/YOUR_NUMBER/team/members \
      -H "Authorization: Bearer YOUR_API_KEY"
    ```

    **जवाब में आपको क्या मिलता है:**

    ```json
    {
      "success": true,
      "request_id": "t3amx",
      "members": [
        { "user_id": "a8d2k4m6p1q3r5s", "name": "Ava", "email": "ava@example.com", "role": "owner", "away": false, "in_rotation": false },
        { "user_id": "k3x9q2m7p4z8w1v", "name": "Ben", "email": "ben@example.com", "role": "member", "away": false, "in_rotation": true }
      ],
      "count": 2,
      "auto_assign": "round_robin"
    }
    ```

    `away: true` का मतलब है कि ऑटो-असाइन नियम फ़िलहाल उस व्यक्ति को छोड़ देता है; `in_rotation: true` का मतलब है कि round robin उन्हें बातचीतें देता है।

    फिर `PUT /conversations/{contact}/assignee` (scope `messages:send`)। `assignee` में यह दिया जा सकता है:

    - सूची से एक `user_id` या एक `email`,
    - `"auto"`: नंबर का ऑटो-असाइन नियम चुनता है (चुने गए सदस्यों में round robin, या वापस उस व्यक्ति को जिसने आखिरी बार जवाब दिया)। नियम `off` हो तो कुछ नहीं बदलता,
    - `""`: कोई नहीं।

    <CodeGroup>

    ```bash cURL
    curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/assignee \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"assignee": "auto"}'
    ```

    ```javascript Node.js
    const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/assignee", {
      method: "PUT",
      headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
      body: JSON.stringify({ assignee: "auto" }), // or "k3x9q2m7p4z8w1v", or "ben@example.com"
    });
    console.log(await res.json());
    ```

    ```python Python
    res = requests.put(
        "https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/assignee",
        headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
        json={"assignee": "auto"},  # or "k3x9q2m7p4z8w1v", or "ben@example.com"
        timeout=10,
    )
    print(res.json())
    ```

    </CodeGroup>

    **जवाब में आपको क्या मिलता है:**

    ```json
    {
      "success": true,
      "request_id": "as1gn",
      "conversation": {
        "contact": "61412345678",
        "conversation_id": 1234,
        "name": "John",
        "assignee": "k3x9q2m7p4z8w1v",
        "assignee_name": "Ben",
        "assigned_at": "2026-11-21T01:21:01.000Z",
        "assigned_by": "auto",
        "status": "open",
        "status_at": null,
        "status_by": null
      }
    }
    ```

    Ben को पुश अलर्ट मिलता है (अगर उन्होंने अलर्ट चालू किए हैं), Inbox में एक गतिविधि पंक्ति दिखती है जैसे `API (Support bot) assigned this to Ben`, और हर webhook को `conversation.assigned` मिलता है।

    owner और assignee दो अलग फ़ील्ड हैं: owner बताता है कि स्वचालित जवाब दूर रहेंगे या नहीं, assignee बताता है कि टीम के किस व्यक्ति के पास चैट है।
  </Step>
  <Step title="टीम के लिए नोट छोड़ें">
    `POST /conversations/{contact}/notes` (scope `messages:send`) एक आंतरिक नोट जोड़ता है: टीम उसे Inbox थ्रेड में पीले नोट के रूप में देखती है, मैसेज के साथ समय के क्रम में। ग्राहक इसे कभी नहीं देखता। 1 से 4000 अक्षर।

    <CodeGroup>

    ```bash cURL
    curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/notes \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"text": "Bot handover: customer asked for a person. Order 1234, wants to move the delivery to Monday."}'
    ```

    ```javascript Node.js
    await fetch("https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/notes", {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
      body: JSON.stringify({ text: "Bot handover: customer asked for a person. Order 1234, wants to move the delivery to Monday." }),
    });
    ```

    ```python Python
    requests.post(
        "https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/notes",
        headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
        json={"text": "Bot handover: customer asked for a person. Order 1234, wants to move the delivery to Monday."},
        timeout=10,
    )
    ```

    </CodeGroup>

    **जवाब में आपको क्या मिलता है:**

    ```json
    {
      "success": true,
      "request_id": "n0te1",
      "contact": "61412345678",
      "conversation_id": 1234,
      "note": {
        "id": 88,
        "kind": "note",
        "text": "Bot handover: customer asked for a person. Order 1234, wants to move the delivery to Monday.",
        "actor": "api:Support bot",
        "actor_name": "API (Support bot)",
        "assignee": null,
        "assignee_name": null,
        "at": "2026-11-21T01:21:02.000Z"
      }
    }
    ```

    नोट idempotent नहीं है: दोबारा कोशिश करने पर दूसरा जुड़ जाता है। इसे हर हैंडओवर में एक बार जोड़ें (नीचे का कोड इसे owner सेट होने के बाद जोड़ता है, और दोबारा कोशिश नहीं करता)।
  </Step>
</Steps>

## जब किसी व्यक्ति के पास चैट हो

- **आपकी टीम जवाब देती है** [डैशबोर्ड](https://www.app2email.com/dashboard) के Inbox से, ईमेल से (जब ईमेल फ़ॉरवर्डिंग चालू हो: owner कोई भी हो, यह जारी रहती है), या API से `POST /messages` के ज़रिए।
- **आपका बॉट चुप रहता है।** वह हर जवाब से पहले `owner` पढ़ता है और जब तक वह `human` या `paused` है, कुछ नहीं करता।
- **app2email का ऑटो रिप्लाई और A2A / OpenClaw एजेंट** संपर्क को छोड़ देते हैं। A2A / OpenClaw एजेंट के लिए यह नंबर की सेटिंग `a2a.respect_owner` पर निर्भर है (डिफ़ॉल्ट रूप से चालू; `GET /settings/number` इसे दिखाता है)।
- **AI जवाब** ग्राहक को केवल तब जवाब देते हैं जब बातचीत का कोई owner न हो, किसी ऐप या ऑटोमेशन ने जवाब न दिया हो, और WhatsApp का अपना AI चैट को न थामे हो।
- **24 घंटे की विंडो अब भी मायने रखती है।** किसी व्यक्ति का free-form जवाब केवल तब काम करता है जब विंडो खुली हो। विंडो बंद होने के बाद भेजा गया ईमेल जवाब रोक लिया जाता है: जब तक संपर्क "Show reply" पर टैप नहीं करता, `GET /conversations/{contact}` में `held_replies` `true` रहता है। विंडो के बाद चैट को फिर से केवल मंज़ूर टेम्पलेट शुरू करता है।

`GET /conversations?assignee=k3x9q2m7p4z8w1v&status=open` (scope `messages:read`) एक व्यक्ति की खुली चैट की सूची देता है; `assignee=none` बिना असाइन वाली चैट की। हर प्रविष्टि में `owner` (सामान्य रूटिंग के लिए छोड़ा गया), `assignee`, `assignee_name`, `status` और `window_open` होते हैं।

## चैट बॉट को लौटाएं

तीन तरीके हैं, और आप सभी इस्तेमाल कर सकते हैं:

1. **सीधे तौर पर**, `PUT /conversations/{contact}/owner` और `"owner": ""` से। कोई व्यक्ति डैशबोर्ड पर भी owner बदल सकता है (तब इवेंट में `set_by` `dashboard` होता है)।
2. **समय से**, हैंडओवर के `until_minutes` से। उसके बाद `owner` फिर से `""` पढ़ा जाता है और `owner_set` अब भी दिखाता है कि क्या सेट किया गया था।
3. **जब टीम चैट को सुलझा हुआ चिह्नित करती है।** `"status": "solved"` के साथ `PUT /conversations/{contact}/status` (या Inbox में "Solved") `conversation.status_changed` भेजता है; आपका बॉट इस पर owner को वापस `""` करके प्रतिक्रिया देता है।

<CodeGroup>

```bash cURL
# Mark it solved (it leaves the Inbox's Open view)
curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/status \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status": "solved"}'

# Back to normal routing: the bot answers again
curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678/owner \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"owner": "", "reason": "solved by the team"}'
```

```javascript Node.js
const headers = { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" };
const base = "https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678";

await fetch(`${base}/status`, { method: "PUT", headers, body: JSON.stringify({ status: "solved" }) });
await fetch(`${base}/owner`, { method: "PUT", headers, body: JSON.stringify({ owner: "", reason: "solved by the team" }) });
```

```python Python
base = "https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678"
headers = {"Authorization": f"Bearer {os.environ['API_KEY']}"}

requests.put(f"{base}/status", headers=headers, json={"status": "solved"}, timeout=10)
requests.put(f"{base}/owner", headers=headers, json={"owner": "", "reason": "solved by the team"}, timeout=10)
```

</CodeGroup>

**status कॉल से आपको क्या मिलता है:**

```json
{
  "success": true,
  "request_id": "s0lvd",
  "conversation": {
    "contact": "61412345678",
    "conversation_id": 1234,
    "name": "John",
    "assignee": "k3x9q2m7p4z8w1v",
    "assignee_name": "Ben",
    "assigned_at": "2026-11-21T01:21:01.000Z",
    "assigned_by": "auto",
    "status": "solved",
    "status_at": "2026-11-21T02:15:00.000Z",
    "status_by": "api:Support bot"
  }
}
```

संपर्क का नया मैसेज सुलझी हुई बातचीत को अपने आप फिर खोल देता है (`by` `contact` के साथ `conversation.status_changed`)। जवाब भेजने से status नहीं बदलता।

<Warning>
किसी व्यक्ति से चैट अपने आप वापस न लें। उसे केवल ऐसे संकेत पर लौटाएं जिस पर आपकी टीम सहमत है (सुलझ गई, तय समय, या किसी व्यक्ति का अपना फ़ैसला)। `owner_set_by` बताता है कि owner किसने सेट किया।
</Warning>

## हैंडओवर का पूरा कोड

यह [API से WhatsApp चैटबॉट बनाएं](/guides/how-to-whatsapp-chatbot) के बॉट में हैंडओवर जोड़ता है। यह हस्ताक्षर जांचता है, जिन इवेंट को संभाल चुका है उन्हें छोड़ देता है, जब तक कोई व्यक्ति चैट का owner है चुप रहता है, मांगने पर चैट सौंपता है, और टीम के उसे सुलझा हुआ चिह्नित करने पर चैट लौटा देता है। पहले `NUMBER` (आपका WhatsApp नंबर, अंक), `API_KEY` और `WEBHOOK_SECRET` (आपके webhook का `whsec_...` मान) सेट करें।

<Tabs>
  <Tab title="Node.js (Express)">

```javascript handoff.mjs
// Node.js 18 or newer.  npm install express   then   node handoff.mjs
import crypto from "node:crypto";
import express from "express";

const { NUMBER, API_KEY, WEBHOOK_SECRET, PORT = 3000 } = process.env;
const API = `https://api.app2email.com/v1/${NUMBER}`;
const ASKS_FOR_PERSON = /\b(human|person|someone|staff|manager)\b/i;
const done = new Set(); // handled event ids: use a database table or Redis in production

function verify(raw, header, secret) {
  const t = /(?:^|,)\s*t=(\d+)/.exec(header ?? "")?.[1];
  const v1 = [...(header ?? "").matchAll(/(?:^|,)\s*v1=([0-9a-f]+)/g)].map((m) => m[1]); // two during a secret change
  if (!t || v1.length === 0 || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
  const expected = crypto.createHmac("sha256", secret).update(t + ".").update(raw).digest("hex");
  return v1.some((v) => v.length === expected.length && crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
}

async function api(method, path, body, idempotencyKey) {
  for (let attempt = 1; ; attempt++) {
    const res = await fetch(API + path, {
      method,
      signal: AbortSignal.timeout(4000),
      headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json",
                 ...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}) },
      body: body ? JSON.stringify(body) : undefined,
    });
    const json = await res.json();
    if (res.ok) return json;
    const code = json.error?.code;
    const wait = Number(res.headers.get("Retry-After") ?? 1);
    if (code === "rate_limited" && attempt < 3 && wait <= 3) { await new Promise((r) => setTimeout(r, wait * 1000)); continue; }
    if (res.status >= 500 || res.status === 429) throw new Error(`${code} ${json.request_id}`);
    console.warn(method, path, code, json.error?.how_to_fix, json.request_id);
    return json;
  }
}

const later = (promise, what) => promise.catch((err) => console.error(`${what} failed:`, err.message));

function wantsPerson(m) {
  return m.interactive?.id === "person" || m.button?.payload === "person" ||
         (m.type === "text" && ASKS_FOR_PERSON.test(m.text ?? ""));
}

async function handOver(m, conv) {
  const to = m.from || m.from_user_id;
  const contact = encodeURIComponent(to);
  const reason = "customer asked for a person";
  const summary = `${conv.name ?? "The customer"} wrote: "${(m.text ?? "").slice(0, 300)}"`;
  // 1. The owner first: from now on no automatic answer reaches this contact. A failure here is retried.
  await api("PUT", `/conversations/${contact}/owner`, { owner: "human", reason, summary, until_minutes: 480 });
  // 2. The rest is best effort: logged, never retried, so nothing is done twice.
  if (conv.window_open) {
    await later(api("POST", "/messages", { to, type: "text",
      text: { body: "Thanks! A person from our team will answer you here soon." } }, `handoff-${m.message_id}`), "message");
  }
  await later(api("PUT", `/conversations/${contact}/assignee`, { assignee: "auto" }), "assign");
  await later(api("POST", `/conversations/${contact}/notes`, { text: `Bot handover: ${reason}. ${summary}` }), "note");
}

async function onMessage(m) {
  const contact = encodeURIComponent(m.from || m.from_user_id);
  const conv = await api("GET", `/conversations/${contact}`);
  if (conv.owner && conv.owner !== "agent") return; // a person has it, or it is paused: stay quiet
  if (wantsPerson(m)) return handOver(m, conv);
  // ... your bot's normal answer goes here (see the chatbot guide)
}

async function onSolved(d) {
  const contact = encodeURIComponent(d.contact);
  const conv = await api("GET", `/conversations/${contact}`);
  if (conv.owner === "human") {
    await api("PUT", `/conversations/${contact}/owner`, { owner: "", reason: "solved by the team" });
  }
}

const app = express();
app.post("/webhook", express.raw({ type: "application/json" }), async (req, res) => {
  if (!verify(req.body, req.get("X-App2email-Signature"), WEBHOOK_SECRET)) return res.sendStatus(401);
  const event = JSON.parse(req.body);
  if (event.test || done.has(event.id)) return res.sendStatus(200);
  try {
    const d = event.data;
    if (event.type === "message.received") await onMessage(d);
    if (event.type === "conversation.status_changed" && d.status === "solved") await onSolved(d);
    if (event.type === "conversation.owner_changed") {
      console.log(`${d.contact}: ${d.previous_owner || "normal"} -> ${d.owner || "normal"} (${d.set_by ?? "?"})`);
    }
    if (event.type === "ai.handover") console.log(`AI handed ${d.contact} to the team: ${d.reason}`);
    done.add(event.id); // only after it worked: a failed event comes again
    res.sendStatus(200);
  } catch (err) {
    console.error("not handled, app2email will send it again:", event.id, err.message);
    res.sendStatus(503);
  }
});
app.listen(PORT, () => console.log(`handoff bot on http://localhost:${PORT}/webhook`));
```

  </Tab>
  <Tab title="Python (Flask)">

```python handoff.py
# Python 3.9 or newer.  pip install flask requests   then   flask --app handoff run --port 3000
import hashlib, hmac, json, os, re, time
from urllib.parse import quote
import requests
from flask import Flask, request

NUMBER, API_KEY, SECRET = os.environ["NUMBER"], os.environ["API_KEY"], os.environ["WEBHOOK_SECRET"]
API = f"https://api.app2email.com/v1/{NUMBER}"
ASKS_FOR_PERSON = re.compile(r"\b(human|person|someone|staff|manager)\b", re.I)
done = set()  # handled event ids: use a database table or Redis in production

def verify(raw: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    t = re.search(r"(?:^|,)\s*t=(\d+)", header or "")
    v1 = re.findall(r"(?:^|,)\s*v1=([0-9a-f]+)", header or "")  # two during a secret change
    if not t or not v1 or abs(time.time() - int(t.group(1))) > tolerance:
        return False
    expected = hmac.new(secret.encode(), t.group(1).encode() + b"." + raw, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(v, expected) for v in v1)

def api(method, path, body=None, idempotency_key=None):
    headers = {"Authorization": f"Bearer {API_KEY}"}
    if idempotency_key:
        headers["Idempotency-Key"] = idempotency_key
    for attempt in (1, 2, 3):
        res = requests.request(method, API + path, json=body, headers=headers, timeout=4)
        data = res.json()
        if res.ok:
            return data
        code = data.get("error", {}).get("code")
        wait = int(res.headers.get("Retry-After", "1"))
        if code == "rate_limited" and attempt < 3 and wait <= 3:
            time.sleep(wait)
            continue
        if res.status_code >= 500 or res.status_code == 429:
            raise RuntimeError(f"{code} {data.get('request_id')}")
        print("not done:", method, path, code, data.get("error", {}).get("how_to_fix"), data.get("request_id"))
        return data

def later(what, *args, **kwargs):
    try:
        api(*args, **kwargs)
    except Exception as err:  # best effort: logged, never retried
        print(what, "failed:", err)

def wants_person(m):
    return ((m.get("interactive") or {}).get("id") == "person"
            or (m.get("button") or {}).get("payload") == "person"
            or (m.get("type") == "text" and ASKS_FOR_PERSON.search(m.get("text") or "")))

def hand_over(m, conv):
    to = m.get("from") or m.get("from_user_id")
    contact = quote(to, safe="")
    reason = "customer asked for a person"
    summary = f'{conv.get("name") or "The customer"} wrote: "{(m.get("text") or "")[:300]}"'
    # 1. The owner first: from now on no automatic answer reaches this contact. A failure here is retried.
    api("PUT", f"/conversations/{contact}/owner",
        {"owner": "human", "reason": reason, "summary": summary, "until_minutes": 480})
    # 2. The rest is best effort, so nothing is done twice.
    if conv.get("window_open"):
        later("message", "POST", "/messages", {"to": to, "type": "text",
              "text": {"body": "Thanks! A person from our team will answer you here soon."}},
              idempotency_key=f"handoff-{m['message_id']}")
    later("assign", "PUT", f"/conversations/{contact}/assignee", {"assignee": "auto"})
    later("note", "POST", f"/conversations/{contact}/notes", {"text": f"Bot handover: {reason}. {summary}"})

def on_message(m):
    contact = quote(m.get("from") or m.get("from_user_id"), safe="")
    conv = api("GET", f"/conversations/{contact}")
    if conv.get("owner") and conv.get("owner") != "agent":
        return  # a person has it, or it is paused: stay quiet
    if wants_person(m):
        return hand_over(m, conv)
    # ... your bot's normal answer goes here (see the chatbot guide)

def on_solved(d):
    contact = quote(d["contact"], safe="")
    conv = api("GET", f"/conversations/{contact}")
    if conv.get("owner") == "human":
        api("PUT", f"/conversations/{contact}/owner", {"owner": "", "reason": "solved by the team"})

app = Flask(__name__)

@app.post("/webhook")
def webhook():
    raw = request.get_data()
    if not verify(raw, request.headers.get("X-App2email-Signature"), SECRET):
        return "bad signature", 401
    event = json.loads(raw)
    if event.get("test") or event["id"] in done:
        return "", 200
    d = event.get("data", {})
    try:
        if event["type"] == "message.received":
            on_message(d)
        elif event["type"] == "conversation.status_changed" and d.get("status") == "solved":
            on_solved(d)
        elif event["type"] == "conversation.owner_changed":
            print(f'{d["contact"]}: {d.get("previous_owner") or "normal"} -> {d.get("owner") or "normal"} ({d.get("set_by")})')
        elif event["type"] == "ai.handover":
            print(f'AI handed {d["contact"]} to the team: {d.get("reason")}')
    except Exception as err:
        print("not handled, app2email will send it again:", event["id"], err)
        return "", 503
    done.add(event["id"])  # only after it worked: a failed event comes again
    return "", 200
```

  </Tab>
</Tabs>

**यह ऐसे क्यों बना है:**

- owner **पहले** सेट होता है। अगर वह कॉल 5xx या रेट लिमिट से विफल हो, तो बॉट 503 देता है और app2email इवेंट बाद में फिर भेजता है; तब तक और कुछ नहीं हुआ होता, इसलिए दोबारा कोशिश साफ़ शुरू होती है।
- owner सेट होने के बाद मैसेज, असाइनमेंट और नोट **best effort** हैं: विफलता लॉग होती है, दोबारा नहीं आज़माई जाती। पूरे इवेंट की दोबारा कोशिश में `owner` `human` मिलेगा और जांच पर रुक जाएगा, इसलिए ये चरण वैसे भी दो बार नहीं चलेंगे।
- `"assignee": "auto"` नंबर का ऑटो-असाइन नियम इस्तेमाल करता है। प्लान में टीम inbox के बिना यह 403 `team_inbox_not_in_plan` देता है, जो लॉग होता है; हैंडओवर खुद फिर भी काम करता है।
- "solved" पर चैट लौटाना केवल `human` वाले owner को छूता है। जो चैट `paused` है, वह paused ही रहती है।

## नतीजा

WhatsApp पर ग्राहक को अपना मैसेज दिखता है, फिर "Thanks! A person from our team will answer you here soon.", फिर आपकी टीम के किसी व्यक्ति का जवाब। Inbox में चैट Ben को असाइन है, और हैंडओवर के ऊपर पीला नोट है।

आपके webhook को ये इवेंट मिलते हैं, हर एक सामान्य envelope (`id`, `type`, `created`, `number`, `data`) में, और type हेडर `X-App2email-Event` में भी होता है:

| इवेंट | कब |
| --- | --- |
| `conversation.owner_changed` | owner बदला: human, agent, paused या सामान्य पर वापस; या WhatsApp के AI एजेंट ने बातचीत ली या आगे दी (owner `whatsapp_ai`) |
| `conversation.assigned` | चैट टीम के किसी व्यक्ति को दी गई, या किसी को नहीं: Inbox में, ऑटो-असाइन नियम से, किसी ऑटोमेशन से, AI जवाब से या API से |
| `conversation.note_added` | एक आंतरिक नोट जोड़ा गया (संपर्क को कभी नहीं भेजा जाता) |
| `conversation.status_changed` | चैट सुलझी हुई चिह्नित हुई, या फिर खुली (किसी व्यक्ति, API, या संपर्क के नए मैसेज से) |
| `ai.handover` | AI जवाबों ने चैट किसी व्यक्ति को सौंपी: हैंडओवर मैसेज भेजा गया और owner `human` हो गया |
| `message.status` | "कोई व्यक्ति जवाब देगा" वाला मैसेज भेजा गया, डिलीवर हुआ और पढ़ा गया |

**किसी व्यक्ति ने कमान संभाली** (`conversation.owner_changed`):

```json
{
  "id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
  "type": "conversation.owner_changed",
  "created": "2026-11-21T01:21:00.000Z",
  "number": "4976659348270",
  "data": {
    "contact": "61412345678",
    "owner": "human",
    "reason": "customer asked for a person",
    "summary": "John wrote: \"Can I talk to a person about my delivery?\"",
    "until": "2026-11-21T09:21:00.000Z",
    "set_by": "api",
    "timestamp": "2026-11-21T01:21:00.000Z"
  }
}
```

**बॉट के पास वापस** (वही इवेंट, owner खाली):

```json
{
  "id": "evt_Xq3k9m2Lw8Rt5Yp1Zs07",
  "type": "conversation.owner_changed",
  "created": "2026-11-21T02:15:01.000Z",
  "number": "4976659348270",
  "data": {
    "contact": "61412345678",
    "owner": "",
    "previous_owner": "human",
    "reason": "solved by the team",
    "set_by": "api",
    "timestamp": "2026-11-21T02:15:01.000Z"
  }
}
```

**असाइन हुई** (`conversation.assigned`):

```json
{
  "id": "evt_Team3k9m2Lw8Rt5Yp1Z01",
  "type": "conversation.assigned",
  "created": "2026-11-21T01:21:01.000Z",
  "number": "4976659348270",
  "data": {
    "contact": "61412345678",
    "conversation_id": 1234,
    "assignee": "k3x9q2m7p4z8w1v",
    "assignee_name": "Ben",
    "previous_assignee": null,
    "by": "auto",
    "timestamp": "2026-11-21T01:21:01.000Z"
  }
}
```

**सुलझी** (`conversation.status_changed`):

```json
{
  "id": "evt_Team3k9m2Lw8Rt5Yp1Z02",
  "type": "conversation.status_changed",
  "created": "2026-11-21T02:15:00.000Z",
  "number": "4976659348270",
  "data": {
    "contact": "61412345678",
    "conversation_id": 1234,
    "status": "solved",
    "previous_status": "open",
    "by": "dashboard:ben@example.com",
    "timestamp": "2026-11-21T02:15:00.000Z"
  }
}
```

`by` और `set_by` बताते हैं कि बदलाव किसने किया: `dashboard:<email>`, `api:<key name>` या `api`, `automation: <rule>`, `ai`, `auto` (ऑटो-असाइन नियम), या `contact` (नए मैसेज ने चैट फिर खोली)।

<Note>
रेफ़रेंस यह नहीं कहता कि `until_minutes` खत्म होने पर कोई इवेंट भेजा जाता है। उसके लिए किसी इवेंट पर भरोसा न करें: हर जवाब से पहले `GET /conversations/{contact}` से `owner` पढ़ें, जैसा ऊपर का कोड करता है।
</Note>

<a id="ai-answers-hand-over-by-themselves"></a>

## AI जवाब खुद चैट सौंपते हैं

अगर नंबर आपके अपने बॉट के बजाय **AI जवाब** (app2email का असिस्टेंट, Professional प्लान और ट्रायल पर) इस्तेमाल करता है, तो हैंडओवर पहले से बना हुआ है। असिस्टेंट चैट किसी व्यक्ति को तब सौंपता है जब उसकी जानकारी सवाल को कवर नहीं करती, ग्राहक किसी व्यक्ति को मांगता है, या अनुरोध को टीम की ज़रूरत होती है। वह हैंडओवर मैसेज भेजता है, owner को `human` सेट करता है, और `ai.handover` भेजता है:

```json
{
  "id": "evt_Ai3k9m2Lw8Rt5Yp1Zs002",
  "type": "ai.handover",
  "created": "2026-11-21T01:00:00.000Z",
  "number": "4976659348270",
  "data": {
    "contact": "61412345678",
    "conversation_id": 1234,
    "message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBI5QTNDQTVCM0Q0Q0Q2RTY3RTgA",
    "text": "Thanks, a person from our team will reply soon.",
    "reason": "the customer asks for a refund",
    "model": "claude-haiku-5-5",
    "owner": "human",
    "timestamp": "2026-11-21T01:00:00.000Z"
  }
}
```

जब हैंडओवर मैसेज भेजा नहीं जा सका, तब `message_id` null होता है। ग्राहक को मिलने वाला टेक्स्ट `GET /ai-answers/settings` में `handover_text` है (खाली का मतलब डिफ़ॉल्ट; `handover_text_sent` दिखाता है कि क्या भेजा जाता है)। इसे `PUT /ai-answers/settings` से बदला जाता है (scope `settings:manage`, sandbox key से नहीं)।

चैट ऑटोमेशन नियम भी चैट सौंप सकते हैं: "hand to a person" उनके चरणों में से एक है, असाइन करने, सुलझा हुआ चिह्नित करने और नोट जोड़ने के साथ।

## किसी AI एजेंट से हैंडओवर कराएं

MCP सर्वर `https://api.app2email.com/mcp/conversations` में इस गाइड के कॉल टूल के रूप में हैं, उसी `Authorization: Bearer` key के साथ: `get_conversation`, `get_conversation_messages`, `set_conversation_owner`, `list_team_members`, `assign_conversation`, `set_conversation_status`, `add_conversation_note`, `list_conversation_notes`। पूरे सर्वर `https://api.app2email.com/mcp` में भी ये हैं। देखें [MCP से AI एजेंट को अपना WhatsApp चलाने दें](/guides/how-to-ai-agent-mcp) और [MCP](/api/mcp)।

एजेंटों का नियम आपके बॉट जैसा ही है: जब संपर्क किसी व्यक्ति को मांगे या एजेंट मदद न कर सके, तो छोटे `reason` और एक `summary` के साथ `human` सेट करें, और जो चैट किसी व्यक्ति ने ली है उसे वापस (`agent` या `""`) न लें, जब तक उपयोगकर्ता ने न कहा हो।

## प्रोडक्शन चेकलिस्ट

<Check>
**हर इवेंट सत्यापित करें।** हेडर `X-App2email-Signature` है `t=<unix seconds>,v1=<hex>`: `t`, एक बिंदु और raw body का HMAC-SHA256, webhook के signing secret (`whsec_...`, prefix सहित) को key बनाकर। हर `v1=` जांचें (secret बदलने के बाद पुराना secret रखा जाए तो दो होते हैं), constant time में तुलना करें, और पुराने `t` को अस्वीकार करें (ऊपर का कोड 5 मिनट की छूट देता है)। `X-Hub-Signature-256` (`sha256=` और raw body का HMAC-SHA256, जैसे Meta हस्ताक्षर करता है) भी मौजूद है, केवल मौजूदा secret के साथ। अधिक: [Webhooks](/api/webhooks)।
</Check>

<Check>
**जल्दी जवाब दें और दोहराव हटाएं।** 10 सेकंड के भीतर 2xx लौटाएं; रीडायरेक्ट फ़ॉलो नहीं किए जाते। विफल इवेंट 10 s, 1 min, 5 min, 30 min, 1, 2, 4, 8 और 16 घंटे बाद फिर भेजा जाता है। इवेंट `id` (`X-App2email-Delivery` में भी) हर बार वही रहता है: संभाले हुए ids को कम से कम दो दिन रखें, मेमोरी के बजाय database या Redis में।
</Check>

<Check>
**हर जवाब से पहले owner जांचें।** जवाब केवल तब दें जब `owner` `""` हो (या आपका अपना `agent` निशान)। इवेंट देर से या क्रम से बाहर आ सकते हैं, इसलिए आखिरी देखे `conversation.owner_changed` पर भरोसा करने के बजाय बातचीत पढ़ें, और इवेंट को `data.timestamp` से क्रमबद्ध करें।
</Check>

<Check>
**एक बार सौंपें।** पहले owner सेट करें; उसे दोहराना सुरक्षित है। "कोई व्यक्ति जवाब देगा" मैसेज को ग्राहक के `message_id` से बनी `Idempotency-Key` के साथ भेजें (24 घंटे के भीतर वही key दोबारा नहीं भेजी जाती; जवाब `Idempotent-Replayed: true` के साथ लौटता है)। नोट और `"assignee": "auto"` idempotent नहीं हैं: उन्हें एक बार चलाएं।
</Check>

<Check>
**रेट लिमिट का सम्मान करें।** हर जवाब में `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (फिर से पूरा होने तक के सेकंड) और `X-RateLimit-Policy` होते हैं। सीमा पार होने पर: `Retry-After` हेडर और `error.retry_after_seconds` के साथ 429 `rate_limited`; उतनी देर रुकें, फिर दोबारा कोशिश करें। अधिक: [Limits](/api/limits)।
</Check>

<Check>
**24 घंटे की विंडो का ध्यान रखें।** आपके बॉट का "कोई व्यक्ति जवाब देगा" मैसेज और आपकी टीम के जवाब free-form मैसेज हैं: वे ग्राहक के आखिरी मैसेज के 24 घंटे के भीतर ही काम करते हैं (app2email 15 मिनट पहले रुक जाता है; `window_closes_at` ठीक समय है)। उसके बाद केवल मंज़ूर टेम्पलेट। अगर कोई व्यक्ति चैट देर से उठाता है, तो पहले `window_open` जांचें।
</Check>

<Check>
**opt-out का सम्मान करें।** Do Not Call सूची free-form जवाबों पर लागू नहीं होती, क्योंकि ग्राहक ने आपको लिखा है। अपवाद: जब उनका आखिरी मैसेज खुद opt-out था, तब जवाब पर 403 `recipient_opted_out` आता है जब तक वे फिर न लिखें। ऐसा होने पर `contact.opted_out` आपको बताता है।
</Check>

<Check>
**हर नंबर पर एक ही जवाब देने वाला।** ऑटो रिप्लाई, चैट ऑटोमेशन, AI जवाब और आपका बॉट सब एक जैसे मैसेज देखते हैं। तय करें कि कौन जवाब देगा। `agent` का owner AI जवाबों को दूर रखता है, जब तक आपका बॉट संपर्क को संभाल रहा है।
</Check>

<Check>
**सारांश लोगों के लिए लिखें।** `summary` उन लोगों तक पहुंचता है जो WhatsApp मैसेज ईमेल से पढ़ते हैं, और नोट Inbox में पढ़ा जाता है। उन्हें छोटा और उपयोगी रखें: ऑर्डर नंबर, ग्राहक क्या चाहता है, बॉट ने क्या पहले ही आज़माया। उनमें कभी गोपनीय जानकारी या भुगतान विवरण न डालें।
</Check>

<Check>
**न्यूनतम पहुंच।** हैंडओवर को `messages:send` और `messages:read` चाहिए। key को अपने सर्वर पर रखें, कभी वेब पेज या लॉग में नहीं। key को आपके सर्वर के IP पतों तक सीमित किया जा सकता है, उस पर दैनिक सीमा लगाई जा सकती है, या वह समाप्त हो सकती है।
</Check>

## अगर यह काम न करे

| आपको क्या दिखता है | कारण | समाधान |
| --- | --- | --- |
| 400 `invalid_owner` | `owner` `""`, `agent`, `human` या `paused` नहीं है | जैसे `{"owner": "human", "reason": "customer asked for a person"}` भेजें; बाकी फ़ील्ड वैकल्पिक हैं |
| 400 `invalid_json` | body वैध JSON नहीं है | कोटेशन, कॉमा और ब्रैकेट जांचें |
| 400 `invalid_phone` | URL में संपर्क न नंबर है न business-scoped user id | पूरा नंबर इस्तेमाल करें, पहले देश कोड, या `from_user_id` |
| 404 `conversation_not_found` | इस संपर्क के साथ अभी कोई बातचीत नहीं | business-scoped user id वाली बातचीत तब शुरू होती है जब संपर्क नंबर पर लिखता है |
| 400 `invalid_assignee` | `assignee` न user id है, न ईमेल, न `auto` और न `""` | `GET /team/members` से `user_id` या `email` लें |
| 422 `not_a_member` | वह व्यक्ति नंबर का owner नहीं है, न ही जवाब दे सकने वाला सदस्य (viewers को असाइन नहीं किया जा सकता) | `GET /team/members` बताता है कि किसे असाइन किया जा सकता है |
| 400 `invalid_conversation_status` | `status` `open` या `solved` नहीं है | `{"status": "solved"}` या `{"status": "open"}` भेजें |
| 400 `invalid_conversation_note` | नोट खाली है या 4000 अक्षर से लंबा है | 1 से 4000 अक्षर के साथ `{"text": "..."}` भेजें |
| 403 `team_inbox_not_in_plan` | असाइनमेंट, नोट और खुला / सुलझा नंबर के प्लान में नहीं हैं | ये Trial और Professional प्लान के साथ आते हैं; owner इनके बिना काम करता है |
| 503 `team_database_pending` | टीम inbox app2email की ओर से database अपडेट का इंतज़ार कर रहा है | बाद में फिर कोशिश करें; बाकी सब पहले जैसा चलता है |
| 403 `insufficient_scope` | key में एक अनुमति नहीं है (`details.required_scope`) | `messages:send` और `messages:read` वाली key इस्तेमाल करें |
| 403 `not_in_instant_sandbox` | डेमो नंबर में यह कॉल नहीं है (जैसे टीम वाले कॉल) | अपने नंबर पर sandbox key, या सामान्य key इस्तेमाल करें |
| 403 `plan_not_allowed`, `service_not_live` | कोई सशुल्क प्लान नहीं, या सेवा चालू नहीं | प्लान चुनें; रुकी हुई सेवा Settings पेज पर "Go Live" से चालू होती है |
| 422 `outside_24h_window` | ग्राहक ने आखिरी बार 24 घंटे से ज़्यादा पहले लिखा था | इसके बजाय मंज़ूर टेम्पलेट भेजें |
| 403 `recipient_opted_out` | ग्राहक का आखिरी मैसेज opt-out था | जब तक वे फिर न लिखें, जवाब न दें |
| 429 `rate_limited` | इस key के लिए बहुत ज़्यादा कॉल | `Retry-After` सेकंड रुकें, फिर दोबारा कोशिश करें |
| हैंडओवर के बाद भी बॉट जवाब देता है | आपका बॉट `owner` नहीं जांचता, या नंबर पर कोई और जवाब देने वाला चल रहा है | हर जवाब से पहले `GET /conversations/{contact}` पढ़ें; डैशबोर्ड पर ऑटो रिप्लाई, ऑटोमेशन और AI जवाब जांचें |
| A2A / OpenClaw एजेंट अब भी जवाब देता है | नंबर की सेटिंग `a2a.respect_owner` बंद है | `GET /settings/number` इसे दिखाता है; यह डिफ़ॉल्ट रूप से चालू है |

हर जवाब में एक `request_id` होता है। `GET /requests/{request_id}` दिखाता है कि उसके लिए क्या लॉग हुआ (त्रुटियां और बदलाव करने वाली रिक्वेस्ट, 30 दिन रखी जाती हैं), और support@app2email.com भी उसे ढूंढ सकता है। सभी कोड: [Errors](/api/errors)।

## अक्सर पूछे जाने वाले सवाल

<AccordionGroup>
  <Accordion title="human और paused में क्या अंतर है?">
    app2email के स्वचालित जवाबों के लिए कोई नहीं: दोनों में ऑटो रिप्लाई, A2A / OpenClaw एजेंट और AI जवाब संपर्क को छोड़ देते हैं। जब चैट किसी व्यक्ति के पास हो तब `human` इस्तेमाल करें, और `paused` तब जब आप बस इस संपर्क के लिए स्वचालित जवाब कुछ समय रोकना चाहें, जैसे कुछ जांचते समय। दोनों `until_minutes` से अपने आप खत्म हो सकते हैं।
  </Accordion>
  <Accordion title="agent का क्या मतलब है, और क्या मेरे बॉट को इसे सेट करना चाहिए?">
    `agent` बताता है कि कोई ऑटोमेशन संपर्क का owner है। यह बाकी सबके लिए एक निशान है, और AI जवाबों को दूर रखता है (वे केवल बिना owner वाली बातचीत का जवाब देते हैं)। इसे तब सेट करें जब कई सिस्टम एक ही नंबर देखते हों और आप चाहते हों कि वे देखें कि आपका बॉट इस संपर्क के साथ किसी काम के बीच में है। बॉट का काम पूरा होने पर फिर `""` सेट करें।
  </Accordion>
  <Accordion title="owner whatsapp_ai क्या है?">
    WhatsApp का अपना AI एजेंट बातचीत को थामे हुए है। `conversation.owner_changed` बताता है कि वह चैट कब लेता है या आगे देता है (`set_by` `whatsapp`, `handover` `control_taken` या `control_passed` के साथ)। जब तक वह चैट थामे है, जवाब तभी जाता है जब वह बातचीत आगे दे दे।
  </Accordion>
  <Accordion title="क्या ग्राहक के कभी लिखने से पहले मैं चैट सौंप सकता हूं?">
    हां, फ़ोन नंबर के लिए: जिस नंबर से कभी संपर्क नहीं हुआ उसका बातचीत रिकॉर्ड बन जाता है, इसलिए owner पहले सेट किया जा सकता है। business-scoped user id के लिए संपर्क को पहले लिखना होगा (वरना 404 `conversation_not_found`)।
  </Accordion>
  <Accordion title="क्या मैं WhatsApp नंबर के बिना पहचान को आज़मा सकता हूं?">
    हां। तुरंत मिलने वाला sandbox (`POST https://api.app2email.com/v1/account/sandbox`, बिना key, बिना body) डेमो नंबर `12025550100` के लिए एक key (`a2es_...`, 7 दिन वैध) देता है। इसका नकली ग्राहक `12025550105` किसी व्यक्ति को मांगता है। इवेंट `GET /events?wait=25` से पढ़ें और owner `PUT /conversations/{contact}/owner` से सेट करें; टीम वाले कॉल वहां नहीं हैं। WhatsApp तक कुछ नहीं पहुंचता।
  </Accordion>
  <Accordion title="क्या मैं सार्वजनिक URL के बिना इवेंट पा सकता हूं?">
    हां: `GET /events?wait=25` (scope `messages:read`) वही इवेंट लौटाता है जो webhook को मिलते हैं, उसी `id` के साथ। जवाब का `cursor` रखें और अगली कॉल पर उसे `after` के रूप में दें। [API से WhatsApp चैटबॉट बनाएं](/guides/how-to-whatsapp-chatbot) में यह लूप दिखाया गया है।
  </Accordion>
  <Accordion title="मैं कैसे देखूं कि चैट में क्या हुआ?">
    `GET /conversations/{contact}/notes?include_activity=true` (scope `messages:read`) नोट की सूची देता है, सबसे पुराना पहले, और `include_activity=true` जोड़ने पर गतिविधि पंक्तियां भी (`assigned`, `unassigned`, `solved`, `reopened`)। `GET /conversations/{phone}/messages` दोनों दिशाओं के मैसेज की सूची देता है।
  </Accordion>
</AccordionGroup>

## और how-to गाइड

<CardGroup cols={2}>
  <Card title="API से WhatsApp चैटबॉट बनाएं" href="/guides/how-to-whatsapp-chatbot">
    हस्ताक्षरित webhook पर मैसेज पाएं और अपने ही कोड से उनका जवाब दें।
  </Card>
  <Card title="टेम्पलेट से ऑर्डर और अपॉइंटमेंट नोटिफ़िकेशन भेजें" href="/guides/how-to-order-notifications">
    पुष्टि और रिमाइंडर के लिए मंज़ूर utility टेम्पलेट, डिलीवरी स्टेटस के साथ।
  </Card>
  <Card title="opt-in का सम्मान करने वाला मार्केटिंग ब्रॉडकास्ट भेजें" href="/guides/how-to-marketing-broadcast">
    एक टेम्पलेट सूची या सेगमेंट को, सहमति रिकॉर्ड और Do Not Call सूची के साथ।
  </Card>
  <Card title="MCP से AI एजेंट को अपना WhatsApp चलाने दें" href="/guides/how-to-ai-agent-mcp">
    Claude या किसी दूसरे एजेंट को सीमित scope वाली key और अनुमोदन के साथ अपने नंबर से जोड़ें।
  </Card>
  <Card title="WhatsApp चैट के भीतर भुगतान मांगें" href="/guides/how-to-payment-links">
    चैट में पेमेंट लिंक भेजें और भुगतान होने पर जानें।
  </Card>
</CardGroup>

[सभी how-to गाइड](https://www.app2email.com/docs#how-to)
