网淘吧来吧,欢迎您!

ManyChat

2026-03-29 新闻来源:网淘吧 围观:13
电脑广告
手机广告

ManyChat

通过托管认证访问ManyChat API,管理订阅用户、标签、自定义字段、流程,并通过聊天自动化发送消息。

快速开始

# Get page info
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/manychat/fb/page/getInfo')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

基础URL

https://gateway.maton.ai/manychat/{native-api-path}

{native-api-path}替换为实际的ManyChat API端点路径。网关将请求代理至api.manychat.com并自动注入您的API令牌。

认证

所有请求都要求在Authorization头部中包含Maton API密钥:

Authorization: Bearer $MATON_API_KEY

环境变量:将您的API密钥设置为MATON_API_KEY

export MATON_API_KEY="YOUR_API_KEY"

获取您的API密钥

  1. 登录或前往maton.ai
  2. 创建账户前往
  3. maton.ai/settings

复制您的API密钥

在以下网址管理您的ManyChat连接https://ctrl.maton.ai

列出连接

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=manychat&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

创建连接

python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'manychat'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

获取连接

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

响应:

{
  "connection": {
    "connection_id": "21fd90f9-5935-43cd-b6c8-bde9d915ca80",
    "status": "ACTIVE",
    "creation_time": "2025-12-08T07:20:53.488460Z",
    "last_updated_time": "2026-01-31T20:03:32.593153Z",
    "url": "https://connect.maton.ai/?session_token=...",
    "app": "manychat",
    "metadata": {}
  }
}

通过连接URL提供您的ManyChat API密钥以完成连接。

删除连接

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

指定连接

如果您有多个ManyChat连接,请通过Maton-Connection标头指定要使用哪一个:

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/manychat/fb/page/getInfo')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '21fd90f9-5935-43cd-b6c8-bde9d915ca80')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

如果省略,网关将使用默认(最早创建的)活动连接。

API参考

页面操作

获取页面信息

GET /manychat/fb/page/getInfo

速率限制:每秒100次查询

响应:

{
  "status": "success",
  "data": {
    "id": 123456789,
    "name": "Page Name",
    "category": "Business",
    "avatar_link": "https://...",
    "username": "pagename",
    "about": "About text",
    "description": "Page description",
    "is_pro": true,
    "timezone": "America/New_York"
  }
}

标签操作

列出标签

GET /manychat/fb/page/getTags

速率限制:每秒100次查询

响应:

{
  "status": "success",
  "data": [
    {"id": 1, "name": "VIP"},
    {"id": 2, "name": "Customer"}
  ]
}

创建标签

POST /manychat/fb/page/createTag
Content-Type: application/json

{
  "name": "New Tag"
}

速率限制:每秒10次查询

从页面移除标签

POST /manychat/fb/page/removeTag
Content-Type: application/json

{
  "tag_id": 123
}

速率限制:每秒10次查询。从页面及所有订阅者处移除标签。

按名称移除标签

POST /manychat/fb/page/removeTagByName
Content-Type: application/json

{
  "tag_name": "Old Tag"
}

速率限制:每秒10次查询

自定义字段操作

列出自定义字段

GET /manychat/fb/page/getCustomFields

速率限制:每秒100次查询

响应:

{
  "status": "success",
  "data": [
    {"id": 1, "name": "phone_number", "type": "text"},
    {"id": 2, "name": "purchase_count", "type": "number"}
  ]
}

创建自定义字段

POST /manychat/fb/page/createCustomField
Content-Type: application/json

{
  "caption": "Phone Number",
  "type": "text",
  "description": "Customer phone number"
}

速率限制:每秒10次查询

字段类型: 文本数字日期日期时间布尔值

机器人字段操作

列出机器人字段

GET /manychat/fb/page/getBotFields

速率限制:每秒100次查询

创建机器人字段

POST /manychat/fb/page/createBotField
Content-Type: application/json

{
  "name": "counter",
  "type": "number",
  "description": "Global counter",
  "value": 0
}

速率限制:每秒10次查询

设置机器人字段

POST /manychat/fb/page/setBotField
Content-Type: application/json

{
  "field_id": 123,
  "field_value": 42
}

速率限制:每秒10次查询

按名称设置机器人字段

POST /manychat/fb/page/setBotFieldByName
Content-Type: application/json

{
  "field_name": "counter",
  "field_value": 42
}

速率限制:每秒10次查询

设置多个机器人字段

POST /manychat/fb/page/setBotFields
Content-Type: application/json

{
  "fields": [
    {"field_id": 123, "field_value": "value1"},
    {"field_name": "field2", "field_value": "value2"}
  ]
}

速率限制:每秒10次查询。每次请求最多20个字段。

流程操作

列出流程

GET /manychat/fb/page/getFlows

速率限制:每秒10次查询

响应:

{
  "status": "success",
  "data": {
    "flows": [
      {"ns": "content123456", "name": "Welcome Flow", "folder_id": 1}
    ],
    "folders": [
      {"id": 1, "name": "Main Folder"}
    ]
  }
}

增长工具

列出增长工具

GET /manychat/fb/page/getGrowthTools

速率限制:每秒100次查询

OTN主题

列出OTN主题

GET /manychat/fb/page/getOtnTopics

速率限制:每秒100次查询

订阅者操作

获取订阅者信息

GET /manychat/fb/subscriber/getInfo?subscriber_id=123456789

速率限制:每秒10次查询

响应:

{
  "status": "success",
  "data": {
    "id": 123456789,
    "name": "John Doe",
    "first_name": "John",
    "last_name": "Doe",
    "gender": "male",
    "profile_pic": "https://...",
    "subscribed": "2025-01-15T10:30:00Z",
    "last_interaction": "2025-02-01T14:20:00Z",
    "tags": [{"id": 1, "name": "VIP"}],
    "custom_fields": [{"id": 1, "name": "phone", "value": "+1234567890"}]
  }
}

按姓名查找订阅者

GET /manychat/fb/subscriber/findByName?name=John%20Doe

速率限制:每秒10次查询。最多返回100条结果。

按自定义字段查找订阅者

GET /manychat/fb/subscriber/findByCustomField?field_id=123&field_value=value

速率限制:每秒10次查询。适用于文本和数字字段。最多返回100条结果。

按系统字段查找订阅者

GET /manychat/fb/subscriber/findBySystemField?email=john@example.com
GET /manychat/fb/subscriber/findBySystemField?phone=+1234567890

速率限制:每秒50次查询。需设置以下任一参数:电子邮箱电话号码参数。

按用户引用获取订阅者

GET /manychat/fb/subscriber/getInfoByUserRef?user_ref=123456

创建订阅者

POST /manychat/fb/subscriber/createSubscriber
Content-Type: application/json

{
  "first_name": "John",
  "last_name": "Doe",
  "phone": "+1234567890",
  "email": "john@example.com",
  "gender": "male",
  "has_opt_in_sms": true,
  "has_opt_in_email": true,
  "consent_phrase": "I agree to receive messages"
}

速率限制:每秒10次查询

注意:导入包含电话号码或电子邮箱的订阅者需要获得ManyChat的特殊权限。请联系ManyChat支持团队为您的账户启用此功能。

更新订阅者

POST /manychat/fb/subscriber/updateSubscriber
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "first_name": "John",
  "last_name": "Smith",
  "phone": "+1234567890",
  "email": "john.smith@example.com"
}

速率限制:每秒10次查询

为订阅者添加标签

POST /manychat/fb/subscriber/addTag
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "tag_id": 1
}

速率限制:每秒10次查询

按名称添加标签

POST /manychat/fb/subscriber/addTagByName
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "tag_name": "VIP"
}

速率限制:每秒10次查询

移除订阅者标签

POST /manychat/fb/subscriber/removeTag
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "tag_id": 1
}

速率限制:每秒10次查询

按名称移除标签

POST /manychat/fb/subscriber/removeTagByName
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "tag_name": "VIP"
}

速率限制:每秒10次查询

设置自定义字段

POST /manychat/fb/subscriber/setCustomField
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "field_id": 1,
  "field_value": "+1234567890"
}

速率限制:每秒10次查询

按名称设置自定义字段

POST /manychat/fb/subscriber/setCustomFieldByName
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "field_name": "phone_number",
  "field_value": "+1234567890"
}

速率限制:每秒10次查询

设置多个自定义字段

POST /manychat/fb/subscriber/setCustomFields
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "fields": [
    {"field_id": 1, "field_value": "value1"},
    {"field_name": "field2", "field_value": "value2"}
  ]
}

速率限制:每秒10次查询。每次请求最多20个字段。

通过签名请求验证订阅者

POST /manychat/fb/subscriber/verifyBySignedRequest
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "signed_request": "signed_request_token"
}

速率限制:每秒10次查询

发送操作

发送内容

POST /manychat/fb/sending/sendContent
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "data": {
    "version": "v2",
    "content": {
      "messages": [
        {
          "type": "text",
          "text": "Hello! How can I help you today?"
        }
      ]
    }
  },
  "message_tag": "CONFIRMED_EVENT_UPDATE"
}

速率限制:每秒25次查询

消息标签:用于在24小时消息窗口外发送时必需

  • 已确认事件更新
  • 购买后更新
  • 账户更新

一次性通知(OTN):

{
  "subscriber_id": 123456789,
  "data": {...},
  "otn_topic_name": "Price Drop Alert"
}

按用户参考发送内容

POST /manychat/fb/sending/sendContentByUserRef
Content-Type: application/json

{
  "user_ref": 123456,
  "data": {
    "version": "v2",
    "content": {
      "messages": [
        {
          "type": "text",
          "text": "Welcome!"
        }
      ]
    }
  }
}

速率限制:每秒25次查询

发送流程

POST /manychat/fb/sending/sendFlow
Content-Type: application/json

{
  "subscriber_id": 123456789,
  "flow_ns": "content123456"
}

速率限制:每秒20次查询,每用户每小时最多100次

消息内容格式

ManyChat 使用结构化内容格式发送消息:

文本消息

{
  "version": "v2",
  "content": {
    "messages": [
      {
        "type": "text",
        "text": "Your message here"
      }
    ]
  }
}

图片消息

{
  "version": "v2",
  "content": {
    "messages": [
      {
        "type": "image",
        "url": "https://example.com/image.jpg"
      }
    ]
  }
}

快速回复

{
  "version": "v2",
  "content": {
    "messages": [
      {
        "type": "text",
        "text": "Choose an option:",
        "quick_replies": [
          {"type": "node", "caption": "Option 1", "target": "content123"},
          {"type": "node", "caption": "Option 2", "target": "content456"}
        ]
      }
    ]
  }
}

按钮

{
  "version": "v2",
  "content": {
    "messages": [
      {
        "type": "text",
        "text": "Click a button:",
        "buttons": [
          {"type": "url", "caption": "Visit Website", "url": "https://example.com"},
          {"type": "flow", "caption": "Start Flow", "target": "content123"}
        ]
      }
    ]
  }
}

代码示例

JavaScript

// Get page info
const response = await fetch(
  'https://gateway.maton.ai/manychat/fb/page/getInfo',
  {
    headers: {
      'Authorization': `Bearer ${process.env.MATON_API_KEY}`
    }
  }
);
const data = await response.json();

// Send a message
const sendResponse = await fetch(
  'https://gateway.maton.ai/manychat/fb/sending/sendContent',
  {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.MATON_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      subscriber_id: 123456789,
      data: {
        version: 'v2',
        content: {
          messages: [{ type: 'text', text: 'Hello!' }]
        }
      }
    })
  }
);

Python

import os
import requests

# Get page info
response = requests.get(
    'https://gateway.maton.ai/manychat/fb/page/getInfo',
    headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'}
)
data = response.json()

# Send a message
send_response = requests.post(
    'https://gateway.maton.ai/manychat/fb/sending/sendContent',
    headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'},
    json={
        'subscriber_id': 123456789,
        'data': {
            'version': 'v2',
            'content': {
                'messages': [{'type': 'text', 'text': 'Hello!'}]
            }
        }
    }
)

注意事项

  • 订阅者ID在您的ManyChat页面内是唯一的
  • 流程命名空间(flow_ns)用于标识特定的自动化流程
  • 当在24小时消息窗口之外发送消息时,消息标签参数是必需的
  • 一次性通知(OTN)允许每个主题订阅发送一条消息
  • 大多数POST端点成功时会返回{"status": "success"}重要提示:使用curl命令时,若URL包含方括号,请使用
  • curl -g以禁用通配符解析重要提示:将curl输出通过管道传递给
  • jq或其他命令时,某些shell环境中$MATON_API_KEY等环境变量可能无法正确展开错误处理

状态码

含义400
缺少ManyChat连接401
Maton API密钥无效或缺失429
请求频率受限4xx/5xx
来自ManyChat API的透传错误ManyChat错误代码

代码

Code含义
2011未找到订阅用户
2012未找到用户引用
3011消息内容无效
3021需要消息标签
3031未找到OTN主题

故障排除:API密钥问题

  1. 检查MATON_API_KEY环境变量是否已设置:
echo $MATON_API_KEY
  1. 通过列出连接来验证API密钥是否有效:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

故障排除:无效的应用名称

  1. 确保您的URL路径以manychat开头。例如:
  • 正确:https://gateway.maton.ai/manychat/fb/page/getInfo
  • 错误:https://gateway.maton.ai/fb/page/getInfo

资源

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第316664名访客 今日有11篇新文章/评论