set your twilio things from settings

This commit is contained in:
m5r
2021-10-16 01:25:13 +02:00
parent 3cc6f35071
commit 2afd3554b3
18 changed files with 242 additions and 483 deletions

View File

@ -0,0 +1,21 @@
import { NotFoundError, resolver } from "blitz";
import db from "db";
import twilio from "twilio";
export default resolver.pipe(resolver.authorize(), async (_ = null, { session }) => {
if (!session.orgId) {
throw new NotFoundError();
}
const organization = await db.organization.findFirst({ where: { id: session.orgId } });
if (!organization || !organization.twilioAccountSid || !organization.twilioAuthToken) {
throw new NotFoundError();
}
const incomingPhoneNumbers = await twilio(
organization.twilioAccountSid,
organization.twilioAuthToken,
).incomingPhoneNumbers.list();
return incomingPhoneNumbers.map(({ phoneNumber, sid }) => ({ phoneNumber, sid }));
});