12 implement twilio sms #37

Merged
BenjaminPalko merged 26 commits from 12-implement-twilio-sms into master 2025-01-02 20:11:28 -05:00
4 changed files with 9 additions and 41 deletions
Showing only changes of commit 8f6873304d - Show all commits

View file

@ -0,0 +1,4 @@
import { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN } from '$env/static/private';
import twilio from 'twilio';
export const TwilioClient = twilio(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);

View file

@ -1 +1 @@
export * from './twilio.config';
export * from './client';

View file

@ -1,30 +0,0 @@
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
import { env } from '$env/dynamic/private';
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
import { PhoneRegex } from '$lib/regex';
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
import { logger } from '$lib/server/logger';
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
import { z } from 'zod';
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
export interface TwilioConfiguration {
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
twilio_account_sid: string;
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
twilio_auth_token: string;
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
twilio_phone_number: string;
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
}
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
export const TwilioConfig = (): TwilioConfiguration => {
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
const { success, data, error } = z
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
.object({
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
TWILIO_ACCOUNT_SID: z.string().min(1),
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
TWILIO_AUTH_TOKEN: z.string().min(1),
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
TWILIO_PHONE_NUMBER: z.string().regex(PhoneRegex),
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
})
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
.safeParse(env);
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
if (!success) {
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
logger.error(error.message);
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
}
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
return {
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
twilio_account_sid: data!.TWILIO_ACCOUNT_SID,
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
twilio_auth_token: data!.TWILIO_AUTH_TOKEN,
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
twilio_phone_number: data!.TWILIO_PHONE_NUMBER,
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
};
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`
};
piopi commented 2024-12-31 22:43:38 -05:00 (Migrated from github.com)
Review

Add a script instead + add it to bun dev

Add a script instead + add it to `bun dev`

View file

@ -1,8 +1,8 @@
import { TWILIO_PHONE_NUMBER } from '$env/static/private';
import { PhoneRegex } from '$lib/regex';
import { logger } from '$lib/server/logger';
import { TwilioConfig } from '$lib/server/twilio';
import { TwilioClient } from '$lib/server/twilio';
import { fail, type Actions } from '@sveltejs/kit';
import twilio from 'twilio';
import zod from 'zod';
export const actions = {
@ -31,17 +31,11 @@ export const actions = {
return fail(400, { error: 'invalid_message' });
}
const twilioConfig = TwilioConfig();
const twilioClient = twilio(
twilioConfig.twilio_account_sid,
twilioConfig.twilio_auth_token
);
try {
const result = await twilioClient.messages.create({
const result = await TwilioClient.messages.create({
to: phone,
body: message,
from: twilioConfig.twilio_phone_number,
from: TWILIO_PHONE_NUMBER,
});
logger.debug(result);
} catch (e) {