narrow-wolf-78445
06/28/2024, 7:05 PMts
import axios, { AxiosRequestConfig } from "axios"
const BOT_PRESS_URL = ''
const API_TOKEN = ''
const INTEGRATION_ID = ''
const BOT_ID = ''
const reqContinuously = async (config: AxiosRequestConfig<any>, field: string) => {
const apiData: any[] = []
try {
const reqObj = axios.get(BOT_PRESS_URL + config.url, {
headers: {
"Authorization" : `Bearer ${API_TOKEN}`,
"x-integration-id" : INTEGRATION_ID,
"x-bot-id" : BOT_ID,
},
params: {
...config.params
},
})
const { data } = await reqObj
apiData.push(...data[field])
const { meta } = data
if (meta.nextToken) {
const nextSearch = await reqContinuously({
...config,
url: config.url,
params: {
...config.params,
nextToken: meta.nextToken,
}
}, field)
apiData.push(...nextSearch)
}
} catch (error) {
console.error(error)
}
return apiData
}
const execute = async () => {
const conversations = await reqContinuously({
url: '/v1/chat/conversations',
}, 'conversations',)
console.log({ totalConversations: conversations.length })
}
execute()
https://cdn.discordapp.com/attachments/1256324645565628416/1256324645695787111/image.png?ex=66805b00&is=667f0980&hm=e2b88329399c9de2d3c569d330f85bc6973914224a62dea77424cd718aeb6b42&narrow-wolf-78445
07/08/2024, 3:29 PM