how to send attachments to agent in amazon connect

0

hello. i am working on amazon connect chat apis in which i recieve message from facebook and send to agent and vise versa. for text below code is working fine but when i try to send the attachment send by the facebook(webhook) to the agent by using sendMessage api. i am getting the invalid body error. Below is my code. i dont know i am doing wright or not? if possible provide documentation link. below is my code:

import aws4 from 'aws4'; import axios from 'axios'; import dotenv from 'dotenv';

const sendMessage = async function (chatConnectionToken, content, isAttachment) { //content = text or url send by faceebook after parsing // isAttachment = flag for text or image
dotenv.config(); console.log(":::::::::::::::::::::::::::::::::::::::::::::::::",content) const credentials = { accessKeyId: process.env.aws_access_key_id, secretAccessKey: process.env.aws_secret_access_key, sessionToken: process.env.aws_session_token, }; let body;

if(isAttachment==='text/markdown') {body = { Content: content, ContentType: isAttachment// 'text/markdown', }; } if (isAttachment!='text/markdown') { // if "image/png"

body= [
  {
    
    ContentType: isAttachment, //"image/png"
    Attachment: {
      FileName: 'attachment.png', // Replace with the attachment file name
      Url: content, // Assuming content is the URL of the attachment
    },
  },
];

}

const opts = { host: 'participant.connect.us-east-1.amazonaws.com', method: 'post', path: '/participant/message', body: JSON.stringify(body), service: 'connect', headers: { 'X-Amz-Bearer': chatConnectionToken, 'Content-Type': 'application/json', }, };

aws4.sign(opts, credentials);

const config = { method: 'post', url: 'https://participant.connect.us-east-1.amazonaws.com/participant/message', headers: opts.headers, data: opts.body, };

try { await axios(config); } catch (error) { console.error('Error sending message:', error); } console.log(body); };

export default sendMessage;

已提问 8 个月前367 查看次数
1 回答
-1

Hello, Thank you for connecting today. I replicated the setup on my end to implement the communication between Facebook Messenger to Amazon Connect CCP. During my replication I checked that the default behaviour allows you to send attachments to the agent from Facebook Messenger, which eventually generates download link for the agent to download the files. Are you trying to implement the default implementation mentioned here.

In addition to that, please note that for sending attachments via your Amazon Connect interaction, you will need to enable attachments for the Amazon Connect CCP.

In addition to that, kindly ensure that you are only sending supported filetypes from the chat.

Hope this helps.

AWS
支持工程师
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则