use twilio api key/secret instead of authToken

This commit is contained in:
m5r
2021-08-08 12:28:19 +08:00
parent 835fcaffcc
commit 6f672bfeb2
11 changed files with 55 additions and 53 deletions

21
integrations/twilio.ts Normal file
View File

@ -0,0 +1,21 @@
import { NotFoundError } from "blitz";
import twilio from "twilio";
import type { Organization } from "db";
type MinimalOrganization = Pick<Organization, "twilioAccountSid" | "twilioApiKey" | "twilioApiSecret">;
export default function getTwilioClient(organization: MinimalOrganization | null): twilio.Twilio {
if (
!organization ||
!organization.twilioAccountSid ||
!organization.twilioApiKey ||
!organization.twilioApiSecret
) {
throw new NotFoundError();
}
return twilio(organization.twilioApiKey, organization.twilioApiSecret, {
accountSid: organization.twilioAccountSid,
});
}