Hello everyone! I hope they are well.
I am trying to generate email interactions from the JavaScript SDK, the problem is that the interaction comes empty, that is, it does not show either body or subject to the agent that takes the interaction as shown in the image below
I tried several things but I didn't find anything that helped me, I'll share the code with you, maybe you'll find something that I didn't.
const authenticate = () => {
return client.loginClientCredentialsGrant(clientId, clientSecret)
.then(() => {
console.log('Authentication successful');
})
.catch(err => {
console.error('Authentication error', err);
throw err;
});
};
const sendEmail = (subject, htmlBody) => {
const conversationsApi = new platformClient.ConversationsApi();
const body = {
queueId: queueId,
toAddress: toAddress,
fromAddress: fromAddress,
provider: provider,
subject: subject,
htmlBody: htmlBody,
direction: direction
};
return conversationsApi.postConversationsEmails(body)
.then(data => {
console.log(`Email sent successfully: ${JSON.stringify(data, null, 2)}`);
})
.catch(err => {
console.error('Error sending email', err);
throw err;
});
};
// Usage example
authenticate()
.then(() => {
const subject = 'New form submitted';
const htmlBody = 'Name: John Doe\nEmail: john.doe@example.com\nMessage: This is a test message.';
return sendEmail(subject, htmlBody);
})
.catch(err => {
console.error('Error', err);
});```
Thank you all!