Extract conversation transcript
This article shows you how to retrieve messages exchanged within a conversation. The aim is to be able to export these messages in Json format.
const APIToken = "xxxxxxxx";
const convID = "xxxxxxxx";
const options = {
"method": "POST",
"headers": {
"Authorization": `Bearer ${APIToken}`,
"Content-Type": "application/json"
},
"body": JSON.stringify({
query: `query MyQuery($conversationId: UUID!) {
conversation(id: $conversationId) {
messages {
edges {
node {
__typename
... on ParticipantConversationMessage {
text
createdAt
author {
__typename
}
}
}
}
}
}
}`,
variables: {
conversationId: convID
}
})
};
fetch("https://api.iadvize.com/graphql", options).then(async (response) => {
let json = await response.json();
let messages = json.data.conversation.messages.edges
.filter(edge => edge.node.__typename === 'ParticipantConversationMessage')
.map(edge => ({
author: edge.node.author.__typename,
text: edge.node.text,
sentDate: edge.node.createdAt
}));
// Do what you want / need
console.log(messages);
});
Last updated