Forked from iamseeley/sendSMS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { email, IAddress } from "https://esm.town/v/std/email";
const carriers: { [key: string]: string } = {
'att': 'txt.att.net',
'tmobile': 'tmomail.net',
'verizon': 'vtext.com',
'sprint': 'messaging.sprintpcs.com'
};
export async function sendSMS(phoneNumber: string, message: string, carrier: string): Promise<void> {
const carrierDomain = carriers[carrier.toLowerCase()];
if (!carrierDomain) {
throw new Error('Unsupported carrier');
}
const to: IAddress = { email: `${phoneNumber}@${carrierDomain}` };
try {
console.log(`Attempting to send SMS to: ${to.email}`);
const result = await email({
to: to,
subject: '!',
text: message,
});
console.log('Email function returned:', result);
console.log('SMS sent successfully');
} catch (error) {
console.error('Error sending SMS:', error);
if (error instanceof Error) {
console.error('Error name:', error.name);
console.error('Error message:', error.message);
console.error('Error stack:', error.stack);
}
}
}
sendSMS('6286284692', '😘😘😘', 'verizon');
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 20, 2024