@stacksjs/sms 0.74.48 → 0.74.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/opt-out.js +1 -1
- package/package.json +6 -6
package/dist/opt-out.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{db,sqlDateTime}from"@stacksjs/database";const STOP_WORDS=new Set(["stop","stopall","unsubscribe","cancel","end","quit"]),START_WORDS=new Set(["start","yes","unstop"]),HELP_WORDS=new Set(["help","info"]);export function normalizePhone(raw){const digits=raw.replace(/[^\d+]/g,"");if(/^\d{10}$/.test(digits))return`+1${digits}`;if(/^1\d{10}$/.test(digits))return`+${digits}`;return digits}export function classifyInboundSms(body){const word=body.trim().toLowerCase().split(/\s+/)[0]??"";if(STOP_WORDS.has(word))return"stop";if(START_WORDS.has(word))return"start";if(HELP_WORDS.has(word))return"help";return"message"}export async function optOutPhone(phone,reason="stop-keyword"){const normalized=normalizePhone(phone);if(!normalized)return;await db.deleteFrom("sms_opt_outs").where("phone","=",normalized).execute();await db.insertInto("sms_opt_outs").values({phone:normalized,reason,opted_out_at:sqlDateTime(new Date),created_at:sqlDateTime(new Date),updated_at:sqlDateTime(new Date)}).execute()}export async function optInPhone(phone){const normalized=normalizePhone(phone);if(!normalized)return;await db.deleteFrom("sms_opt_outs").where("phone","=",normalized).execute()}export async function isPhoneOptedOut(phone){const normalized=normalizePhone(phone);if(!normalized)return!1;return!!await db.selectFrom("sms_opt_outs").where("phone","=",normalized).select(["id"]).executeTakeFirst()}export async function handleInboundSms(input,options={}){const kind=classifyInboundSms(input.body),name=options.appName??"this service";switch(kind){case"stop":await optOutPhone(input.from);return{kind,reply:`You are unsubscribed from ${name} texts. No more messages will be sent. Reply START to resubscribe.`};case"start":await optInPhone(input.from);return{kind,reply:`You are resubscribed to ${name} texts. Reply STOP to unsubscribe.`};case"help":return{kind,reply:`${name}: reply STOP to unsubscribe, START to resubscribe.${options.helpContact?` Contact: ${options.helpContact}`:""}`};default:return{kind}}}
|
|
1
|
+
import{db,sqlDateTime}from"@stacksjs/database/runtime";const STOP_WORDS=new Set(["stop","stopall","unsubscribe","cancel","end","quit"]),START_WORDS=new Set(["start","yes","unstop"]),HELP_WORDS=new Set(["help","info"]);export function normalizePhone(raw){const digits=raw.replace(/[^\d+]/g,"");if(/^\d{10}$/.test(digits))return`+1${digits}`;if(/^1\d{10}$/.test(digits))return`+${digits}`;return digits}export function classifyInboundSms(body){const word=body.trim().toLowerCase().split(/\s+/)[0]??"";if(STOP_WORDS.has(word))return"stop";if(START_WORDS.has(word))return"start";if(HELP_WORDS.has(word))return"help";return"message"}export async function optOutPhone(phone,reason="stop-keyword"){const normalized=normalizePhone(phone);if(!normalized)return;await db.deleteFrom("sms_opt_outs").where("phone","=",normalized).execute();await db.insertInto("sms_opt_outs").values({phone:normalized,reason,opted_out_at:sqlDateTime(new Date),created_at:sqlDateTime(new Date),updated_at:sqlDateTime(new Date)}).execute()}export async function optInPhone(phone){const normalized=normalizePhone(phone);if(!normalized)return;await db.deleteFrom("sms_opt_outs").where("phone","=",normalized).execute()}export async function isPhoneOptedOut(phone){const normalized=normalizePhone(phone);if(!normalized)return!1;return!!await db.selectFrom("sms_opt_outs").where("phone","=",normalized).select(["id"]).executeTakeFirst()}export async function handleInboundSms(input,options={}){const kind=classifyInboundSms(input.body),name=options.appName??"this service";switch(kind){case"stop":await optOutPhone(input.from);return{kind,reply:`You are unsubscribed from ${name} texts. No more messages will be sent. Reply START to resubscribe.`};case"start":await optInPhone(input.from);return{kind,reply:`You are resubscribed to ${name} texts. Reply STOP to unsubscribe.`};case"help":return{kind,reply:`${name}: reply STOP to unsubscribe, START to resubscribe.${options.helpContact?` Contact: ${options.helpContact}`:""}`};default:return{kind}}}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/sms",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.74.
|
|
5
|
+
"version": "0.74.50",
|
|
6
6
|
"description": "The Stacks SMS integration. Painlessly create & manage your inboxes, templates, and send sms.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -63,13 +63,13 @@
|
|
|
63
63
|
"prepublishOnly": "bun run build"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@stacksjs/database": "0.74.
|
|
66
|
+
"@stacksjs/database": "0.74.50"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@stacksjs/cli": "0.74.
|
|
70
|
-
"@stacksjs/config": "0.74.
|
|
71
|
-
"@stacksjs/error-handling": "0.74.
|
|
72
|
-
"@stacksjs/types": "0.74.
|
|
69
|
+
"@stacksjs/cli": "0.74.50",
|
|
70
|
+
"@stacksjs/config": "0.74.50",
|
|
71
|
+
"@stacksjs/error-handling": "0.74.50",
|
|
72
|
+
"@stacksjs/types": "0.74.50",
|
|
73
73
|
"better-dx": "^0.2.24"
|
|
74
74
|
}
|
|
75
75
|
}
|