← back to Dear Bubbe Nextjs

app/api/sms/route.ts

56 lines

import { NextRequest, NextResponse } from 'next/server'

// This is a stub SMS API - in production, you would integrate with Twilio or similar
export async function POST(request: NextRequest) {
  try {
    const { phone, message } = await request.json()
    
    if (!phone || !message) {
      return NextResponse.json(
        { error: 'Phone number and message required' },
        { status: 400 }
      )
    }
    
    // Log SMS request (in production, send via Twilio)
    console.log('[SMS] Would send to:', phone)
    console.log('[SMS] Message:', message.substring(0, 160))
    
    // In production, you would use Twilio like this:
    /*
    const accountSid = process.env.TWILIO_ACCOUNT_SID
    const authToken = process.env.TWILIO_AUTH_TOKEN
    const twilioPhone = process.env.TWILIO_PHONE_NUMBER
    
    const client = require('twilio')(accountSid, authToken)
    
    const result = await client.messages.create({
      body: message,
      from: twilioPhone,
      to: phone
    })
    
    return NextResponse.json({
      success: true,
      messageId: result.sid
    })
    */
    
    // For now, just simulate success
    return NextResponse.json({
      success: true,
      message: 'SMS would be sent (Twilio not configured)',
      simulatedMessage: {
        to: phone,
        body: message.substring(0, 160) + (message.length > 160 ? '...' : '')
      }
    })
    
  } catch (error) {
    console.error('[SMS] Error:', error)
    return NextResponse.json(
      { error: 'Failed to send SMS' },
      { status: 500 }
    )
  }
}