2021-08-30 11:24:05 +00:00
|
|
|
import { getConfig, NotFoundError } from "blitz";
|
2021-08-08 04:28:19 +00:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
2021-08-30 11:24:05 +00:00
|
|
|
|
|
|
|
const { serverRuntimeConfig } = getConfig();
|
|
|
|
|
|
|
|
export const smsUrl = `https://${serverRuntimeConfig.app.baseUrl}/api/webhook/incoming-message`;
|
|
|
|
|
|
|
|
export const voiceUrl = `https://${serverRuntimeConfig.app.baseUrl}/api/webhook/call`;
|
|
|
|
|
|
|
|
export function getTwiMLName() {
|
|
|
|
switch (serverRuntimeConfig.app.baseUrl) {
|
|
|
|
case "local.shellphone.app":
|
|
|
|
return "Shellphone LOCAL";
|
|
|
|
case "dev.shellphone.app":
|
|
|
|
return "Shellphone DEV";
|
|
|
|
case "www.shellphone.app":
|
|
|
|
return "Shellphone";
|
|
|
|
}
|
|
|
|
}
|