shellphone.app/app/utils/twilio.server.ts
2022-05-15 01:29:51 +02:00

17 lines
583 B
TypeScript

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,
});
}