Skip to content

seven-io/medusa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

seven logo

seven SMS for Medusa

Send SMS and place text-to-speech calls from your Medusa commerce backend via the seven gateway.

MIT License npm Medusa 1.x


Features

  • SMS & Voice Service - sevenService.sendSms() / sevenService.sendVoice() available across the Medusa container
  • Subscription-based Sending - Hook into Medusa events (e.g. order.placed) to fire SMS automatically
  • Per-Channel Defaults - Configure default sender, flash flag and JSON-response flag per SMS / Voice channel

Prerequisites

Installation

yarn add @seven.io/medusa
# or
npm install @seven.io/medusa

Configuration

1. Set the API key

SEVEN_API_KEY="<YOUR_API_KEY>"

2. Register the plugin in medusa-config.js

const plugins = [
  // ...
  {
    resolve: '@seven.io/medusa',
    options: {
      apiKey: process.env.SEVEN_API_KEY,
      sms: {
        flash: true,                  // optional flash SMS - https://help.seven.io/en/flash-sms
        from: 'Medusa',               // sender ID - https://help.seven.io/en/set-sender-id
      },
      voice: {
        json: true,                   // detailed JSON response
        from: '+49179876543210',     // verified caller ID or shared number
      },
    },
  },
]

Usage

Resolve the service dynamically

const sevenService = scope.resolve('sevenService')

await sevenService.sendSms({
  from: 'Medusa',
  text: 'Dear customer!',
  to:   '+49179876543210',
})

await sevenService.sendVoice({
  from: '+49179876543210',
  text: 'Dear customer!',
  to:   '+49179876543210',
})

Subscribe to Medusa events

Send an SMS automatically once an order is placed:

export default class SmsSubscriber {
  constructor({ eventBusService, orderService, sevenService }) {
    this.sevenService_ = sevenService
    this.orderService = orderService

    eventBusService.subscribe('order.placed', this.sendSMS)
  }

  sendSMS = async ({ id }) => {
    const { shipping_address } = await this.orderService.retrieve(id, {
      relations: ['shipping_address'],
    })

    if (!shipping_address.phone) return

    this.sevenService_.sendSms({
      from: 'MyStore',
      text: `Thanks for your order #${id}. We will inform you right after shipping.`,
      to:   shipping_address.phone,
    })
  }
}

See the seven SMS and Voice API references for the full parameter list.

Support

Need help? Feel free to contact us or open an issue.

License

MIT

About

Medusa plugin for sending SMS and making text-to-speech calls

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors