Back to Plugins

SMSAPI Notification Provider

A Medusa v2 notification provider plugin for sending SMS messages through SMSAPI.com, enabling automated SMS notifications for orders, shipments, and customer communications.


Overview

This plugin integrates SMSAPI.io with Medusa v2, allowing you to send SMS notifications to customers for various e-commerce events. SMSAPI is a reliable SMS gateway service that provides global SMS delivery capabilities.

Features

Requirements

Installation

Install the plugin using npm:

npm install @yanchesky/medusa-smsapi

Configuration

Environment Variables

Add your SMSAPI credentials to your .env file:

SMSAPI_ACCESS_TOKEN=your_smsapi_access_token
SMSAPI_FROM=YourBrandName

Plugin Configuration

Add the plugin to your medusa-config.ts:

import { Modules } from "@medusajs/framework/utils"

module.exports = defineConfig({
  // ... other config
  modules: {
    [Modules.NOTIFICATION]: {
      resolve: "@medusajs/medusa/notification",
      options: {
        providers: [
          {
            resolve: "@yanchesky/medusa-smsapi",
            id: "smsapi",
            options: {
              channels: ["sms"],
              access_token: process.env.SMSAPI_ACCESS_TOKEN,
              from: process.env.SMSAPI_FROM,
              // Optional settings
              encoding: "utf-8", // Default encoding
              test: false, // Enable test mode
              flash: false, // Send as flash SMS
              normalize: true, // Normalize characters
              fast: false, // Priority sending
            },
          },
        ],
      },
    },
  },
})

Usage

Sending SMS Notifications

Use the notification service to send SMS messages:

import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"

export async function POST(req: MedusaRequest, res: MedusaResponse) {
  const notificationModuleService = req.scope.resolve("notification")

  await notificationModuleService.createNotifications({
    to: "+48123456789", // Phone number with country prefix
    channel: "sms",
    template: "order-placed", // Required but not used by plugin
    data: {
      message: "Your order has been placed successfully!",
    },
  })

  res.json({ success: true })
}

Notification Events

Common use cases for SMS notifications:

Configuration Options

Required Options

Optional Options

Test Mode

Enable test mode to validate your integration without sending actual SMS:

{
  resolve: "@yanchesky/medusa-smsapi",
  options: {
    // ... other options
    test: true, // Test mode enabled
  },
}

In test mode:

Phone Number Format

Always include the country prefix:

// Correct formats
"+48123456789"  // Poland
"+1234567890"   // USA
"+44123456789"  // UK

// Incorrect (missing country prefix)
"123456789"     // Will fail

Message Types

Standard SMS

Regular SMS messages with standard delivery:

{
  flash: false,
  fast: false,
}

Flash SMS

Display immediately on screen without saving:

{
  flash: true,
}

Priority SMS

Higher priority delivery:

{
  fast: true,
}

Character Encoding

The plugin supports various encodings:

Enable character normalization to automatically convert special characters:

{
  normalize: true, // Converts ą→a, ę→e, etc.
}

Long Messages

SMS messages longer than 160 characters are automatically split:

Optionally limit the number of parts:

{
  max_parts: 3, // Maximum 3 SMS parts
}

Best Practices

  1. Test First - Always use test mode before production
  2. Message Length - Keep messages concise to avoid multi-part SMS charges
  3. Country Codes - Always include country prefixes
  4. Sender ID - Use recognizable brand name (max 11 characters)
  5. Credits - Monitor SMSAPI account credits
  6. Error Handling - Implement proper error handling for failed deliveries

Explore More Medusa Plugins

Find more powerful plugins and integrations to enhance your Medusa store. Browse our collection of community-driven solutions.

Free & Open Source
Community Driven
Easy Integration