Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seven-io/medusa
Medusa plugin for sending SMS and making text-to-speech calls
https://github.com/seven-io/medusa
e-commerce medusajs sms
Last synced: 6 days ago
JSON representation
Medusa plugin for sending SMS and making text-to-speech calls
- Host: GitHub
- URL: https://github.com/seven-io/medusa
- Owner: seven-io
- License: mit
- Created: 2021-11-16T11:45:15.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T13:20:11.000Z (11 months ago)
- Last Synced: 2024-06-06T22:50:12.910Z (5 months ago)
- Topics: e-commerce, medusajs, sms
- Language: JavaScript
- Homepage: https://www.seven.io/en/solutions/integrations/medusa/
- Size: 84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-medusajs - Seven - square) ![stars](https://img.shields.io/github/stars/seven-io/medusa) (Uncategorized / Uncategorized)
README
# [seven](https://www.seven.io) plugin for [medusa](https://www.medusajs.com/)
## Installation
### Via Yarn
`yarn add @seven.io/medusa`
### Via NPM
`npm install @seven.io/medusa`
## Setup
After installing, add your credentials to `.env`:
````dotenv
SEVEN_API_KEY="" # see https://help.seven.io/en/api-key-access
````The last step is to add the plugin and its options to the `plugins` array in the `medusa-config.js`
file:```js
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 resolved dynamically for sending SMS and making text-to-speech calls.
Example:
```js
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://www.seven.io/en/docs/gateway/http-api/sms-dispatch/
})// 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://www.seven.io/en/docs/gateway/http-api/voice/
})
```### Subscription based usage
This example demonstrates how to send an SMS after an order has been placed.
````js
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,
})
}
}
````### Support
Need help? Feel free to [contact us](https://www.seven.io/en/company/contact/).
[![MIT](https://img.shields.io/badge/License-MIT-teal.svg)](LICENSE)