const approvalResp = await fetch(`${PLACET_URL}/api/v1/messages`, {
method: 'POST',
headers,
body: JSON.stringify({
channelId: CHANNEL_ID,
text: 'Please review the attached report.',
status: 'warning',
attachmentIds: [attachment.id],
review: {
type: 'approval',
payload: {
options: [
{ id: 'approve', label: 'Approve', style: 'primary' },
{ id: 'reject', label: 'Reject', style: 'danger' },
],
},
},
}),
});
const approvalMsg = await approvalResp.json();
// Long-poll for the review response (up to 30s)
const reviewResp = await fetch(
`${PLACET_URL}/api/v1/reviews/${approvalMsg.id}/wait?channel=${CHANNEL_ID}&timeout=30000`,
{ headers },
);
const review = await reviewResp.json();
if (review.status === 'completed') {
console.log(`Decision: ${review.message.review.response.selectedOption}`);
}