prehistoric-secretary-45200
08/14/2023, 12:30 PMprehistoric-secretary-45200
08/15/2023, 6:28 AMgifted-thailand-51685
08/15/2023, 7:59 AMsteep-wire-96122
08/15/2023, 4:03 PMsteep-wire-96122
08/15/2023, 4:03 PMprehistoric-secretary-45200
08/15/2023, 4:33 PMprehistoric-secretary-45200
08/15/2023, 4:34 PMprehistoric-secretary-45200
08/15/2023, 9:25 PMfamous-jewelry-85388
08/16/2023, 4:43 PMfamous-jewelry-85388
08/16/2023, 4:44 PMfamous-jewelry-85388
08/16/2023, 4:46 PMfamous-jewelry-85388
08/16/2023, 4:46 PMprehistoric-secretary-45200
08/16/2023, 5:02 PMquick-pizza-47743
08/17/2023, 2:43 AMprehistoric-secretary-45200
08/24/2023, 6:51 AMprehistoric-secretary-45200
08/29/2023, 7:35 AMtypescript
const createConversationWithWhatsApp = async (phoneNumber) => {
const url = 'https://api.botpress.cloud/v1/chat/conversations/get-or-create';
const payload = {
channel: "channel",
integrationName: "whatsapp",
tags: {
"whatsapp:userPhone": phoneNumber,
"whatsapp:templateName": "test_template",
"whatsapp:templateLanguage": "de"
}
};
const header = {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer xxxx',
'x-bot-id': event.botId
}
};
const {data} = await axios.post(url, payload, header);
console.log(data);
return data.conversation.id;
}
const queueEntries = await queueTable.findRecords({});
const activeNumbers = queueEntries.filter(e => e.conversationId).map(e => e.phoneNumber);
// Filter the entries where no conversation is started
const filteredEntries = queueEntries.filter(e => !e.conversationId && !activeNumbers.includes(e.phoneNumber));
// Filter to get only one item per phoneNumber
const uniqueEntries = _.uniqBy(filteredEntries, 'phoneNumber');
uniqueEntries.forEach(async e => {
const response = await createConversationWithWhatsApp(e.phoneNumber);
console.log("forEach works");
queueTable.updateRecord(e.id, {conversationId: response.conversation.id});
});
prehistoric-secretary-45200
08/30/2023, 2:44 PM