Readme

💬 Val Town Email-to-SMS

Usage

import { sendSMS } from 'https://esm.town/v/iamseeley/sendSMS'; sendSMS(phoneNumber: string, message: string, carrier: string): Promise<void>

Parameters

  • phoneNumber: The recipient's phone number (string of digits, no spaces or dashes)
  • message: The text message you want to send
  • carrier: The recipient's cell phone carrier.

Supported carriers: 'att' (AT&T), 'tmobile' (T-Mobile), 'verizon' (Verizon), 'sprint' (Sprint)

List of Email-To-SMS Addresses

Comment on this val if you'd like me to add a carrier from the above list!

Example

import { sendSMS } from 'https://esm.town/v/iamseeley/sendSMS'; sendSMS('1234567890', 'Hello from Val Town!', 'verizon');
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
38
39
40
41
42
43
44
45
46
47
48
import { email, IAddress } from "https://esm.town/v/std/email";
import { Resend } from "npm:resend";
const sendEmail = async (email: any, subject: string, message: string) => {
const resend = new Resend(Deno.env.get("resendApiKey"));
if (email) {
resend.emails.send({
from: "onboarding@resend.dev",
to: email,
subject,
html: message,
});
}
console.log(`Email sent to ${email} with subject ${subject}`, message);
};
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 sendEmail(to.email, "SMS", 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("+351962113274", "Hello from Val Town!", "tmobile");
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!
v7
June 27, 2024