store twilio stuff in TwilioAccount table and remodel session data
This commit is contained in:
@ -12,15 +12,24 @@ export default Queue<Payload>("fetch messages", async ({ data }) => {
|
||||
const { phoneNumberId } = data;
|
||||
const phoneNumber = await db.phoneNumber.findUnique({
|
||||
where: { id: phoneNumberId },
|
||||
include: { organization: true },
|
||||
include: {
|
||||
organization: {
|
||||
select: { twilioAccount: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!phoneNumber) {
|
||||
logger.warn(`No phone number found with id=${phoneNumberId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const organization = phoneNumber.organization;
|
||||
const twilioClient = getTwilioClient(organization);
|
||||
const twilioAccount = phoneNumber.organization.twilioAccount;
|
||||
if (!twilioAccount) {
|
||||
logger.warn(`Phone number with id=${phoneNumberId} doesn't have a connected twilio account`);
|
||||
return;
|
||||
}
|
||||
|
||||
const twilioClient = getTwilioClient(twilioAccount);
|
||||
const [sent, received] = await Promise.all([
|
||||
twilioClient.messages.list({ from: phoneNumber.number }),
|
||||
twilioClient.messages.list({ to: phoneNumber.number }),
|
||||
|
@ -12,15 +12,24 @@ export default Queue<Payload>("fetch phone calls", async ({ data }) => {
|
||||
const { phoneNumberId } = data;
|
||||
const phoneNumber = await db.phoneNumber.findUnique({
|
||||
where: { id: phoneNumberId },
|
||||
include: { organization: true },
|
||||
include: {
|
||||
organization: {
|
||||
select: { twilioAccount: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!phoneNumber) {
|
||||
logger.warn(`No phone number found with id=${phoneNumberId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const organization = phoneNumber.organization;
|
||||
const twilioClient = getTwilioClient(organization);
|
||||
const twilioAccount = phoneNumber.organization.twilioAccount;
|
||||
if (!twilioAccount) {
|
||||
logger.warn(`Phone number with id=${phoneNumberId} doesn't have a connected twilio account`);
|
||||
return;
|
||||
}
|
||||
|
||||
const twilioClient = getTwilioClient(twilioAccount);
|
||||
const [callsSent, callsReceived] = await Promise.all([
|
||||
twilioClient.calls.list({ from: phoneNumber.number }),
|
||||
twilioClient.calls.list({ to: phoneNumber.number }),
|
||||
|
Reference in New Issue
Block a user