shellphone.app/app/utils/twilio.server.ts

17 lines
583 B
TypeScript
Raw Normal View History

2022-05-14 23:29:51 +00:00
import twilio from "twilio";
import type { Organization } from "@prisma/client";
import serverConfig from "~/config/config.server";
type MinimalOrganization = Pick<Organization, "twilioSubAccountSid" | "twilioAccountSid">;
export default function getTwilioClient(organization: MinimalOrganization): twilio.Twilio {
if (!organization || !organization.twilioSubAccountSid || !organization.twilioAccountSid) {
throw new Error("unreachable");
}
return twilio(organization.twilioSubAccountSid, serverConfig.twilio.authToken, {
accountSid: organization.twilioAccountSid,
});
}