Medusa

MedusaJS is an open-source, headless e-commerce platform that helps developers create and manage online stores with flexibility and scalability. Unlike traditional e-commerce platforms, MedusaJS offers a backend framework that allows users to customize and extend the functionality of their store while having the freedom to choose any frontend technology for the customer experience. MedusaJS supports features like product management, inventory tracking, order processing, and payment integrations, but is highly extensible, allowing users to add custom plugins and APIs to meet their specific needs. It is ideal for developers looking for a flexible, API-centered solution to create tailored e-commerce systems.

Our plugin enables sending SMS and making text-to-speech calls.

Installation

Via Yarn

yarn add @seven.io/medusa

Via NPM

npm install @seven.io/medusa

Setup

After installation, add your credentials to the .env file:

SEVEN_API_KEY="<YOUR_API_KEY>" # see https://help.seven.io/en/api-key-access

The final step is to add the plugin and its options to the plugins array in the medusa-config.js file:

const plugins = [
    //...
    {
        resolve: '@seven.io/medusa',
        options: {
            apiKey: process.env.SEVEN_API_KEY,
            sms: {
                flash: true, // optionally send as flash - see https://help.seven.io/en/flash-sms
                from: 'Medusa', // sender ID - see https://help.seven.io/en/set-sender-id
            },
            voice: {
                json: true, // if true, the API returns a detailed JSON response
                from: '+49179876543210', // must be verified (see https://app.seven.io/settings#callerid) or a shared number (see https://help.seven.io/en/shared-numbers)
            }
        },
    }
]

Usage

Dynamic Usage

The seven service can be dynamically resolved to send SMS and make text-to-speech calls.

Example:

const sevenService = scope.resolve("sevenService")

// send SMS
sevenService.sendSms({
    from: 'Medusa', // optional
    text: "Dear customer!",
    to: "+49179876543210",
    // optionally add more parameters according to the documentation at https://docs.seven.io/en/rest-api/endpoints/sms#send-sms
})

// make a text-to-speech call
sevenService.sendVoice({
    from: '+49179876543210', // optional
    text: "Dear customer!",
    to: "+49179876543210",
    // optionally add more parameters according to the documentation at https://docs.seven.io/en/rest-api/endpoints/voice#send-voice-call
})

Subscription-Based Usage

This example shows how to send an SMS after 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 your order with ID #${id}. We will inform you right after shipping.`,
            to: shipping_address.phone,
        })
    }
}
Last updated: 5 days ago