feat(plugins): Adds Twilio SMS plugin

This commit is contained in:
Oliver Windall Juhl
2020-09-09 10:52:58 +02:00
committed by GitHub
parent cd39798b4b
commit 35a91ae6a1
11 changed files with 6008 additions and 0 deletions
@@ -0,0 +1,34 @@
import { BaseService } from "medusa-interfaces"
import twilio from "twilio"
class TwilioSmsService extends BaseService {
/**
* @param {Object} options - options defined in `medusa-config.js`
* e.g.
* {
* account_sid: "1234",
* auth_token: "XXX",
* from_number: "+4512345678"
* }
*/
constructor({}, options) {
super()
this.options_ = options
this.twilioClient = twilio(options.account_sid, options.auth_token)
}
/**
* @param {Object} data - Twilio message options
* see: https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource
*/
async sendSms(data) {
return this.twilioClient.messages.create({
from: this.options_.from_number,
...data,
})
}
}
export default TwilioSmsService