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

View File

@@ -0,0 +1,13 @@
{
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-instanceof",
"@babel/plugin-transform-classes"
],
"presets": ["@babel/preset-env"],
"env": {
"test": {
"plugins": ["@babel/plugin-transform-runtime"]
}
}
}

View File

@@ -0,0 +1,9 @@
{
"plugins": ["prettier"],
"extends": ["prettier"],
"rules": {
"prettier/prettier": "error",
"semi": "error",
"no-unused-expressions": "true"
}
}

View File

@@ -0,0 +1,15 @@
/lib
node_modules
.DS_store
.env*
/*.js
!index.js
!jest.config.js
/dist
/api
/services
/models
/subscribers

View File

@@ -0,0 +1,9 @@
/lib
node_modules
.DS_store
.env*
/*.js
!index.js
yarn.lock

View File

@@ -0,0 +1,7 @@
{
"endOfLine": "lf",
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5"
}

View File

@@ -0,0 +1,24 @@
# medusa-plugin-sendgrid
Twilio SMS / Messaging plugin.
## Plugin Options
```
{
account_sid: [twilio messaging account sid] (required),
auth_token: [twilio massaging authentication token] (required),
from_number: [the number used as sender SMS],
}
```
## Dynamic usage
You can resolve the Twilio SMS service to dynamically send SMS's via Twilio.
Example:
```js
const twilioSmsService = scope.resolve("twilioSmsService")
twilioSmsService.sendSms({ to: "+4500112233", body: "Hello world!" })
```

View File

@@ -0,0 +1 @@
// noop

View File

@@ -0,0 +1,3 @@
module.exports = {
testEnvironment: "node",
}

View File

@@ -0,0 +1,43 @@
{
"name": "medusa-plugin-twilio-sms",
"version": "1.0.7",
"description": "Twilio SMS service",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa",
"directory": "packages/medusa-plugin-twilio-sms"
},
"author": "Oliver Juhl",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/node": "^7.7.4",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-transform-instanceof": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.5",
"@babel/register": "^7.7.4",
"@babel/runtime": "^7.9.6",
"cross-env": "^5.2.1",
"eslint": "^6.8.0",
"jest": "^25.5.2"
},
"scripts": {
"build": "babel src -d .",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__",
"test": "jest"
},
"peerDependencies": {
"medusa-interfaces": "1.x"
},
"dependencies": {
"@babel/plugin-transform-classes": "^7.9.5",
"body-parser": "^1.19.0",
"medusa-core-utils": "^1.0.7",
"medusa-test-utils": "^1.0.7",
"twilio": "^3.49.1"
}
}

View File

@@ -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

File diff suppressed because it is too large Load Diff