Send SMS and place text-to-speech calls from your Medusa commerce backend via the seven gateway.
- 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
- Medusa backend
- A seven account with API key (How to get your API key)
yarn add @seven.io/medusa
# or
npm install @seven.io/medusaSEVEN_API_KEY="<YOUR_API_KEY>"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
},
},
},
]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',
})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.
Need help? Feel free to contact us or open an issue.