GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - kotenkodev/twilio-sms-booking-bot: Automated session-based SMS conversational bot for scheduling appointments built with Node.js, Express, and Twilio Messaging API. Features multi-step state machine conversation flows, express-session persistence, keyword resets, live webhook handling, and an interactive terminal chat simulator with zero-dependency automated unit tests.

BranchesTags
Open more actions menu

Latest commit

 

History

10 Commits
10 Commits

Folders and files

NameName
Last commit message
Last commit date
scripts
scripts
 
 
src
src
 
 
test
test
 
 
.env.example
.env.example
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 

Repository files navigation

๐Ÿ“ฑ Twilio SMS Booking Bot

An automated, session-based SMS conversational bot for scheduling fitness and wellness appointments (Gym, Personal Trainer, and Massage), built with Node.js, Express, and the Twilio Messaging API.


๐Ÿš€ Features

  • State Machine Conversation Flow: Guides users through service selection, date picking, time selection, and booking confirmation.
  • Session-Based State Management: Tracks appointment progress per user across multiple SMS exchanges using express-session.
  • Session Reset / Cancel Keywords: Texting reset, restart, cancel, or start over resets the booking state at any time.
  • Interactive Terminal Chat Simulator: Test the complete conversation flow locally in your terminal without needing Twilio credits or cellular delivery.
  • Automated Test Suite: Built-in unit tests verifying matching logic and step progression with zero external test dependencies (node --test).
  • Localtunnel Support: Expose your local development server to the internet to receive live webhooks from Twilio.

๐Ÿ”„ Conversation Flow

graph TD
    A[Incoming SMS] --> B{Active Session?}
    B -->|No / Step 1| C[Show Service Options: Gym, Personal Trainer, Massage]
    B -->|Yes / Step 1| D[Parse Service Type]
    D -->|Match| E[Step 2: Ask for Date/Day]
    D -->|No Match| C
    B -->|Yes / Step 2| F[Parse Day of Week]
    F -->|Match| G[Step 3: Ask for Time: 10am, 11am, 1pm, 4pm]
    F -->|Invalid / Multiple| E
    B -->|Yes / Step 3| H[Parse Time]
    H -->|Match| I[Step 4: Confirm Booking Details]
    H -->|No Match| G
    B -->|Yes / Step 4| J[Display Existing Booking Summary]
Loading

๐Ÿ“ Project Structure

twilio-app-2/
โ”œโ”€โ”€ .env.example              # Template for environment variables
โ”œโ”€โ”€ .gitignore                # Git ignore rules for node_modules, .env, and logs
โ”œโ”€โ”€ package.json              # Dependencies and scripts
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ chatSimulator.js      # Terminal-based chat simulator
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config.js             # Centralized environment config and defaults
โ”‚   โ”œโ”€โ”€ twilioClient.js       # Twilio REST client & outbound SMS sender
โ”‚   โ”œโ”€โ”€ bookingHelper.js      # Parsing algorithms (type, day, time, confirmation)
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ””โ”€โ”€ smsController.js  # Webhook handlers, session machine & health check
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ””โ”€โ”€ smsRoutes.js      # Express route definitions (/test, /health, /receive-sms)
โ”‚   โ””โ”€โ”€ main.js               # Application bootstrap & middleware setup
โ””โ”€โ”€ test/
    โ””โ”€โ”€ bookingHelper.test.js # Unit test suite

โš™๏ธ Environment Variables

Copy .env.example to .env and populate your credentials:

cp .env.example .env
Variable Description Default / Example
PORT Local server port 3000
SESSION_SECRET Secret key for express-session cookie encryption twilio-course-secret
ACCOUNT_SID Twilio Account SID ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AUTH_TOKEN Twilio Auth Token your_auth_token_here
PHONE_NUMBER Your Twilio phone number (E.164 format) +1234567890
MY_NUMBER Your personal phone number for outbound test SMS +380687866398
WEEKDAYS Comma-separated list of valid weekdays monday,tuesday,...

๐Ÿ“ฆ Getting Started

1. Install Dependencies

npm install

2. Run the Development Server

npm run dev

3. Run Automated Tests

npm test

๐Ÿงช Testing the Bot

Option A: Interactive Terminal Simulator (Recommended)

You can test the entire conversation flow locally without making real phone calls or using external tools:

  1. In one terminal, start the server:
    npm run dev
  2. In a second terminal, launch the chat simulator:
    npm run chat
  3. Chat with the bot interactively:
    • Type Hi
    • Type I want the gym
    • Type Wednesday
    • Type 11am
    • Type reset to restart the conversation at any point.

Option B: Local PowerShell / cURL Testing

Simulate incoming Twilio webhooks directly against your local server:

# Step 1: Initialize
curl.exe -X POST http://localhost:3000/receive-sms `
  -H "Content-Type: application/x-www-form-urlencoded" `
  -c cookies.txt -b cookies.txt `
  -d "Body=Hi"

# Step 2: Choose Service
curl.exe -X POST http://localhost:3000/receive-sms `
  -H "Content-Type: application/x-www-form-urlencoded" `
  -c cookies.txt -b cookies.txt `
  -d "Body=I want the gym"

# Step 3: Choose Day
curl.exe -X POST http://localhost:3000/receive-sms `
  -H "Content-Type: application/x-www-form-urlencoded" `
  -c cookies.txt -b cookies.txt `
  -d "Body=Wednesday"

# Step 4: Choose Time
curl.exe -X POST http://localhost:3000/receive-sms `
  -H "Content-Type: application/x-www-form-urlencoded" `
  -c cookies.txt -b cookies.txt `
  -d "Body=11am"

Option C: Live Testing with Real SMS via Twilio

  1. Verify your personal phone number:

    • On a Twilio Trial account, destination numbers must be verified under Twilio Console > Phone Numbers > Verified Caller IDs.
  2. Start the server and Localtunnel:

    # Terminal 1
    npm run dev
    
    # Terminal 2
    npm run tunnel
  3. Configure the Twilio Webhook:

    • Go to Twilio Console > Active Numbers and select your number.
    • Under Messaging Configuration -> A MESSAGE COMES IN:
      • Webhook URL: https://<YOUR-LOCALTUNNEL-URL>/receive-sms
      • HTTP Method: HTTP POST
    • Save changes.
  4. Send an SMS from your verified mobile phone to your Twilio number to start booking!


๐Ÿ“ก API Endpoints

  • GET /health โ€” Health check endpoint returning server status and uptime.
  • GET /test โ€” Smoke test route to verify server connectivity.
  • POST /receive-sms โ€” Twilio inbound messaging webhook (accepts form URL-encoded body, returns TwiML XML).

About

Automated session-based SMS conversational bot for scheduling appointments built with Node.js, Express, and Twilio Messaging API. Features multi-step state machine conversation flows, express-session persistence, keyword resets, live webhook handling, and an interactive terminal chat simulator with zero-dependency automated unit tests.

Topics

chatbotexpressnodejssms-botstate-machinetwiliotwilio-messagingtwilio-smswebhook

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.