消息
消息构成了协议中的会话——它们是您与协议联系人对话的基本构建块。在本页中,我们将深入探讨可用于以编程方式管理消息的不同消息端点。我们将查看如何查询、发送、更新和删除消息。
消息模型
消息模型包含您发送给联系人和群组的消息及附件的所有信息,包括您的联系人对此的反应。
Properties
- Name
id
- Type
- string
- Description
消息的唯一标识符。
- Name
conversation_id
- Type
- string
- Description
消息所属会话的唯一标识符。
- Name
contact
- Type
- object
- Description
发送消息的联系人的联系人对象。
- Name
message
- Type
- string
- Description
消息内容。
- Name
reactions
- Type
- array
- Description
与消息关联的反应对象数组。
- Name
attachments
- Type
- array
- Description
与消息关联的附件对象数组。
- Name
read_at
- Type
- timestamp
- Description
消息被阅读的时间戳。
- Name
created_at
- Type
- timestamp
- Description
消息创建的时间戳。
- Name
updated_at
- Type
- timestamp
- Description
消息最后更新时间的时间戳。
GET/v1/messages
消息
此端点允许您检索所有消息的分页列表(如果提供会话ID,则在该会话中)。默认情况下,每页最多显示十条消息。
可选属性
- Name
conversation_id
- Type
- string
- Description
限制为来自指定会话的消息。
- Name
limit
- Type
- integer
- Description
限制返回的消息数量。
Request
GET
/v1/messagescurl -G https://api.protocol.chat/v1/messages \
-H "Authorization: Bearer {token}" \
-d conversation_id=xgQQXg3hrtjh7AvZ \
-d limit=10
Response
{
"has_more": false,
"data": [
{
"id": "SIuAFUNKdSYHZF2w",
"conversation_id": "xgQQXg3hrtjh7AvZ",
"contact": {
"id": "WAz8eIbvDR60rouK",
"username": "KevinMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/buzzboy.jpg",
"last_active_at": 705103200,
"created_at": 692233200
},
"message": "It’s a nice night for a neck injury.",
"reactions": [],
"attachments": [],
"read_at": 705103200,
"created_at": 692233200,
"updated_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et",
// ..
}
]
}
POST/v1/messages
发送消息
此端点允许您向您的某个会话发送新消息。
必需属性
- Name
conversation_id
- Type
- string
- Description
消息所属会话的唯一标识符。
- Name
message
- Type
- string
- Description
消息内容。
可选属性
- Name
attachments
- Type
- array
- Description
与消息关联的附件对象数组。
Request
POST
/v1/messagescurl https://api.protocol.chat/v1/messages \
-H "Authorization: Bearer {token}" \
-d conversation_id="xgQQXg3hrtjh7AvZ" \
-d message="You’re what the French call ‘les incompetents.’"
Response
{
"id": "gWqY86BMFRiH5o11",
"conversation_id": "xgQQXg3hrtjh7AvZ",
"contact": {
"id": "inEIRvzjC6YLMX3o",
"username": "LinnieMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/linnie.jpg",
"last_active_at": 705103200,
"created_at": 692233200
},
"message": "You’re what the French call ‘les incompetents.’",
"reactions": [],
"attachments": [],
"read_at": null,
"created_at": 692233200,
"updated_at": null
}
GET/v1/messages/:id
检索消息
此端点允许您通过提供消息ID来检索消息。请参阅本页顶部的列表,以查看消息对象包含哪些属性。
Request
GET
/v1/messages/SIuAFUNKdSYHZF2wcurl https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
-H "Authorization: Bearer {token}"
Response
{
"id": "SIuAFUNKdSYHZF2w",
"conversation_id": "xgQQXg3hrtjh7AvZ",
"contact": {
"id": "WAz8eIbvDR60rouK",
"username": "KevinMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/kevin.jpg",
"last_active_at": 705103200,
"created_at": 692233200
},
"message": "I’m traveling with my dad. He’s at a meeting. I hate meetings.",
"reactions": [],
"attachments": [],
"read_at": 705103200,
"created_at": 692233200,
"updated_at": 692233200
}
PUT/v1/messages/:id
更新消息
此端点允许您对消息进行更新。更新的示例包括添加反应、编辑消息或添加附件。
可选属性
- Name
message
- Type
- string
- Description
消息内容。
- Name
reactions
- Type
- array
- Description
与消息关联的反应对象数组。
- Name
attachments
- Type
- array
- Description
与消息关联的附件对象数组。
Request
PUT
/v1/messages/SIuAFUNKdSYHZF2wcurl -X PUT https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
-H "Authorization: Bearer {token}" \
-d reactions[red_angry_face][]="KateMcCallister"
Response
{
"id": "SIuAFUNKdSYHZF2w",
"conversation_id": "xgQQXg3hrtjh7AvZ",
"contact": {
"id": "WAz8eIbvDR60rouK",
"username": "KevinMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/buzzboy.jpg",
"last_active_at": 705103200,
"created_at": 692233200
},
"message": "I'm not apologizing. I'd rather kiss a toilet seat.",
"reactions": [
{
"red_angry_face": [
"KateMcCallister"
]
}
],
"attachments": [],
"read_at": 705103200,
"created_at": 692233200,
"updated_at": 692233200
}
DELETE/v1/messages/:id
删除消息
此端点允许您从会话中删除消息。注意:这将永久删除该消息。
Request
DELETE
/v1/messages/SIuAFUNKdSYHZF2wcurl -X DELETE https://api.protocol.chat/v1/messages/SIuAFUNKdSYHZF2w \
-H "Authorization: Bearer {token}"