附件
附件是您在 Protocol 中分享内容的方式——它们允许您向联系人和群组发送各种文件。在本页中,我们将深入探讨您可以用来管理附件的不同附件端点。我们将研究如何查询、上传、更新和删除附件。
附件模型
附件模型包含有关您发送给联系人和群组的文件的所有信息,包括名称、类型和大小。
属性
- Name
id
- Type
- string
- Description
附件的唯一标识符。
- Name
message_id
- Type
- string
- Description
与附件相关联的消息的唯一标识符。
- Name
filename
- Type
- string
- Description
附件的文件名。
- Name
file_url
- Type
- string
- Description
附件文件的URL。
- Name
file_type
- Type
- string
- Description
附件文件的MIME类型。
- Name
file_size
- Type
- integer
- Description
附件的文件大小,以字节为单位。
- Name
created_at
- Type
- timestamp
- Description
附件创建的时间戳。
GET/v1/attachments
列出所有附件
此端点允许您检索所有附件的分页列表(如果提供了对话ID,则为对话中的附件)。默认情况下,每页最多显示十个附件。
可选属性
- Name
conversation_id
- Type
- string
- Description
限制为来自特定对话的附件。
- Name
limit
- Type
- integer
- Description
限制返回的附件数量。
Request
GET
/v1/attachmentscurl -G https://api.protocol.chat/v1/attachments \
-H "Authorization: Bearer {token}" \
-d conversation_id="xgQQXg3hrtjh7AvZ" \
-d limit=10
Response
{
"has_more": false,
"data": [
{
"id": "Nc6yKKMpcxiiFxp6",
"message_id": "LoPsJaMcPBuFNjg1",
"filename": "Invoice_room_service__Plaza_Hotel.pdf",
"file_url": "https://assets.protocol.chat/attachments/Invoice_room_service__Plaza_Hotel.pdf",
"file_type": "application/pdf",
"file_size": 21352,
"created_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
POST/v1/attachments
创建一个附件
此端点允许您将新附件上传到对话中。请参阅代码示例,了解如何将文件发送到 Protocol API。
所需属性
- Name
file
- Type
- string
- Description
你想要添加为附件的文件。
Request
POST
/v1/attachmentscurl https://api.protocol.chat/v1/attachments \
-H "Authorization: Bearer {token}" \
-F file="../Invoice_room_service__Plaza_Hotel.pdf"
Response
{
"id": "Nc6yKKMpcxiiFxp6",
"message_id": "LoPsJaMcPBuFNjg1",
"filename": "Invoice_room_service__Plaza_Hotel.pdf",
"file_url": "https://assets.protocol.chat/attachments/Invoice_room_service__Plaza_Hotel.pdf",
"file_type": "application/pdf",
"file_size": 21352,
"created_at": 692233200
}
GET/v1/attachments/:id
检索附件
此端点允许您通过提供附件ID来检索附件。请参阅本页顶部的列表,以查看附件对象包含哪些属性。
Request
GET
/v1/attachments/Nc6yKKMpcxiiFxp6curl https://api.protocol.chat/v1/attachments/Nc6yKKMpcxiiFxp6 \
-H "Authorization: Bearer {token}"
Response
{
"id": "Nc6yKKMpcxiiFxp6",
"message_id": "LoPsJaMcPBuFNjg1",
"filename": "Invoice_room_service__Plaza_Hotel.pdf",
"file_url": "https://assets.protocol.chat/attachments/Invoice_room_service__Plaza_Hotel.pdf",
"file_type": "application/pdf",
"file_size": 21352,
"created_at": 692233200
}
PUT/v1/attachments/:id
更新附件
此端点允许您更新附件。目前,唯一支持的更新类型是更改文件名。
可选属性
- Name
filename
- Type
- string
- Description
附件的新文件名。
Request
PUT
/v1/attachments/Nc6yKKMpcxiiFxp6curl -X PUT https://api.protocol.chat/v1/attachments/Nc6yKKMpcxiiFxp6 \
-H "Authorization: Bearer {token}" \
-d filename="Invoice_room_service__Plaza_Hotel_updated.pdf"
Response
{
"id": "Nc6yKKMpcxiiFxp6",
"message_id": "LoPsJaMcPBuFNjg1",
"filename": "Invoice_room_service__Plaza_Hotel.pdf",
"file_url": "https://assets.protocol.chat/attachments/Invoice_room_service__Plaza_Hotel_updated.pdf",
"file_type": "application/pdf",
"file_size": 21352,
"created_at": 692233200
}
DELETE/v1/attachments/:id
删除附件
此端点允许您删除附件。注意:这将永久删除文件。
Request
DELETE
/v1/attachments/Nc6yKKMpcxiiFxp6curl -X DELETE https://api.protocol.chat/v1/attachments/Nc6yKKMpcxiiFxp6 \
-H "Authorization: Bearer {token}"