Skip to content

Instantly share code, notes, and snippets.

@matheuscouto
Created July 4, 2023 11:19
Show Gist options
  • Save matheuscouto/2ef51dee795ebf2ade2f5d72504f95d9 to your computer and use it in GitHub Desktop.
Save matheuscouto/2ef51dee795ebf2ade2f5d72504f95d9 to your computer and use it in GitHub Desktop.
const verifyIsFirstMessage = async (message) => {
const { conversationId, id: messageId } = message;
try {
const messagesAPI = `${BASE_API_URL}/messages?conversationId=${
message.conversationId
}&toTimestamp=${Date.now()}`;
const options = {
method: 'GET',
headers: {
accept: 'application/json',
apikey: apiKey,
},
};
const response = await fetch(messagesAPI, options);
const parsedResponse = await response.json();
return parsedResponse.data[0].id === messageId;
} catch (e) {
log.error(
`Error while listing chat messages for conversation id ${conversationId}`,
e,
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment