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;