A Medusa plugin for sending SMS via SMSAPI.
A notification provider plugin that enables SMS notifications via SMSAPI.com and service for Medusa v2 projects.
npm install @yanchesky/medusa-smsapi# oryarn add @yanchesky/medusa-smsapi
Create or update your file:
SMSAPI_ACCESS_TOKEN=your_smsapi_access_token_hereSMSAPI_FROM=YourBrand
Add the plugin to your :
import { SMSAPIOptions } from '@yanchesky/medusa-smsapi';// ...module.exports = {// ... other configurationsmodules: [// ... other modules{resolve: '@yanchesky/medusa-smsapi/providers/smsapi',dependencies: ['logger'] // Optional in test mode to log sent messagesoptions: {channels: ['sms'], // Required: notification channelsaccess_token: process.env.SMSAPI_ACCESS_TOKEN,from: process.env.SMSAPI_FROM,} satisfies SMSAPIOptions,},],}
import { Modules } from '@medusajs/framework/utils';// ...const notificationService = container.resolve(Modules.NOTIFICATION);await notificationService.createNotifications([{channel: 'sms',to: '48123456789', // Country prefix is requiredtemplate: 'confrimation' // This is required by Medusa but is not used by the plugin.content: {text: "An SMS message"}}])
interface SMSAPIOptions {// Requiredaccess_token: string // Your SMSAPI access tokenfrom: string // Sender name verified by SMSAPIchannels: string[] // Notification channels// Optional Basic Settingsencoding?: string // Message encoding (default: "UTF-8")test?: boolean // Test mode (default: false)api_url?: string // API endpoint (default: "https://smsapi.io/api")// Optional Advanced Settingsflash?: boolean // Flash SMS (default: false)max_parts?: 1-10 // Maximum number of parts a message can be split intonounicode?: boolean // Prevents from sending messages containing special characters.normalize?: boolean // Converts special characters to regular ones. ę -> e; ć -> cfast?: boolean // Send SMS with the highest priority (default: false)}
Enable test mode to validate your setup without sending actual SMS. In test mode a request to API endpoint will be executed validating credentials and logging sent message.
# Run type checkingyarn typecheck# Run lintingyarn lint# Format codeyarn format# Build pluginyarn build
All contributions are welcome! Please follow these steps:
MIT License