# 商家推送

电商机器人的API管理接口，为商家提供了一个有效互动的方式，提高网站的购物体验。 正确集成API管理后，商家将可以以如下方式向主页粉丝主动推送消息:

* 顾客成功下单后，通过 PSID 向其推送一条订单确认回执
* 订单发货/签收时，通过 PSID 向顾客发送物流状态更新提示

## 订单回执

### 接口

```
{
  "request": {
    "method": "send_template",
    "id": "test_1523959671_Od7vuGcb",
    "page_id": "1487925408000967",
    "template_name": "Order Receipt Push"
  },
  "recipient": {
    "id": "<psid>"
  },
  "params": {
    "receipt": {
      "recipient_name": "John Doe",
      "order_number": "U5555",
      "currency": "USD",
      "payment_method": "Visa 2345",
      "order_url": "https://storage.googleapis.com/assets.bothub.ai/bothub/templates/classic_white_shirt.jpg",
      "timestamp": 1523619550,
      "address": {
        "street_1": "UNICEF 125 Maiden Lane",
        "street_2": "11th Floor",
        "city": "New York",
        "postal_code": "10038",
        "state": "NY",
        "country": "US"
      },
      "summary": {
        "subtotal": 138.4,
        "shipping_cost": 0,
        "total_tax": 0,
        "total_cost": 138.4
      },
      "adjustments": [],
      "elements": [
        {
          "title": "Classic White Shirts",
          "subtitle": "100% Soft and Luxurious Cotton",
          "quantity": 2,
          "price": 11.99,
          "currency": "USD",
          "image_url": "https://storage.googleapis.com/assets.bothub.ai/bothub/templates/classic_white_shirt.jpg"
        },
        {
          "title": "Floral Belted Romper",
          "subtitle": "Casual romper featuring striped pattern",
          "quantity": 2,
          "price": 13.89,
          "currency": "USD",
          "image_url": "https://storage.googleapis.com/assets.bothub.ai/bothub/templates/floral_belted_romper.jpg"
        },
        {
          "title": "One Shoulder Bikini Set",
          "subtitle": "Low Waisted",
          "quantity": 2,
          "price": 14.66,
          "currency": "USD",
          "image_url": "https://storage.googleapis.com/assets.bothub.ai/bothub/templates/one_shoulder_bikini_set.jpg"
        },
        {
          "title": "Smocked Mini Dress",
          "subtitle": "Elastic waistband",
          "quantity": 2,
          "price": 15.77,
          "currency": "USD",
          "image_url": "https://storage.googleapis.com/assets.bothub.ai/bothub/templates/smocked_mini_dress.jpg"
        },
        {
          "title": "Twist Tied Top",
          "subtitle": "Easily look good to pair it with anything",
          "quantity": 2,
          "price": 12.89,
          "currency": "USD",
          "image_url": "https://storage.googleapis.com/assets.bothub.ai/bothub/templates/twisted_tied_top.jpg"
        }
      ]
    }
  }
}
```

### **接口说明**

当商户需要向用户推送订单回执时，由商户填充params.receipt数据，Bothub验证数据格式正确后向用户发送消息

### 返回值

**成功**

```
{
  "request_id": "test_1523960126_YKanxh4G",
  "recipient_id": "1602407863220595"
}
```

**失败**

```
{
  "error": {
    "code": 10010,
    "error_subcode": 0,
    "type": "",
    "message": "Recipient not found",
    "request_id": "test_1r6523960126_YKanxh4G"
  }
}
```

### 物流更新

#### 接口 <a href="#jie-kou" id="jie-kou"></a>

```
{
  "request": {
    "method": "send_template",
    "id": "test_1523960374_wERGZIon",
    "page_id": "176029956384795",
    "template_name": "Shipping Status Update Push"
  },
  "recipient": {
    "id": "<psid>"
  },
  "params": {
    "package_number": "zvfVUREPVPUQ1oMl",
    "package_status_description": "Status: enroute by UPS \n Exp. Delivery: 03, Jan, 2018",
    "image_url": "https://unsplash.it/120/120/?random",
    "detailed_tracking_url": "http://shop.bothub.ai",
    "fb_first_name": "Peter",
    "package_status": "shipped"
  }
}
```

### **接口说明**

当商户需要向用户推送物流更新时，由商户填充params数据，其中`package_number`物流单号，`package_status`物流状态，`package_status_description`物流状态详情， `image_url`截图网址， `detailed_tracking_url`物理详情链接，`fb_first_name`用户名，Bothub验证数据格式后向用户发送消息

### 返回值

#### 成功 <a href="#cheng-gong" id="cheng-gong"></a>

```
{
  "request_id": "test_1523960966_EnPC3z5h",
  "recipient_id": "1602407863220595"
}
```

#### 失败 <a href="#shi-bai" id="shi-bai"></a>

```
{
  "error": {
    "code": 10010,
    "error_subcode": 0,
    "type": "",
    "message": "Recipient not found",
    "request_id": "test_1523960966_EnPC3z5h"
  }
}
```
