입력 첨부 처리
REST API를 사용하여 사용자 지정 채널 애플리케이션을 구축하는 경우 입력 첨부 파일로 미디어 파일 전송에 대한 지원을 추가할 수 있습니다.
message 메소드의 요청 본문은 최대 5개의 매체 오브젝트를 지정할 수 있는 attachments 배열을 지원합니다. attachments 배열로 전송되는 미디어 객체는 구성된 메시지 전 처리 웹훅에 의해 가로채서 처리될 수 있습니다.
API를 사용하여 첨부 파일에 액세스하는 방법에 대한 자세한 내용은 API 참조 문서를 참조하십시오.
예
다음 예는 메시지 본문에 " Hello "라는 텍스트와 JPEG 이미지 파일을 첨부 파일로 포함하는 요청 본문을 프리 메시지 웹훅으로 보내는 것을 보여줍니다. 웹훅 요청을 받은 애플리케이션은 어시스턴트가 처리하기 전에 ' attachments 배열을 파싱하고 첨부파일을 처리하여 선택적으로 메시지를 수정할 수 있습니다.
{
"event":{
"name":"message_received"
},
"options":{
},
"payload":{
"input":{
"message_type":"text",
"text":"Hello",
"source":{
"type":"user",
"id":"00000000000000000000000000000000"
},
"options":{
"suggestion_only":false,
"return_context":true
},
"attachments": [
{
"media_type": "image/jpeg",
"url": "https://example.com/yourphoto.jpeg"
}
]
},
"context":{
"global":{
"system":{
"user_id":"00000000000000000000000000000000"
}
},
"integrations":{
"text_messaging":{
"assistant_phone_number":"+12223334444",
"private":{
"user_phone_number":"+14443332222",
"request_id":"00000000-0000-0000-0000-000000000000",
"ip_address":"172.10.10.10"
}
}
}
}
}
}
이 예는 사용자 지정 채널 애플리케이션에서 단일 미디어 첨부 파일을 포함하여 전송하는 상태 저장 ' /message ' 요청을 보여줍니다.
service
.message({
assistant_id: '{assistant_id}',
session_id: '{session_id}',
input: {
message_type: 'text',
text: 'Hello',
attachments: [
{
'media_type': 'image/jpeg',
'url': 'https://example.com/yourphoto.jpeg'
}
]
}
})
.then(res => {
console.log(JSON.stringify(res, null, 2));
})
.catch(err => {
console.log(err);
});
response=service.message(
assistant_id='{assistant_id}',
session_id='{session_id}',
input={
'message_type': 'text',
'text': 'Hello',
'attachments': [
{
'media_type': 'image/jpeg',
'url': 'https://example.com/yourphoto.jpeg'
}
]
}
).get_result()
print(json.dumps(response, indent=2))