feat(plugins): Adds Twilio SMS plugin
This commit is contained in:
committed by
GitHub
parent
cd39798b4b
commit
35a91ae6a1
13
packages/medusa-plugin-twilio-sms/.babelrc
Normal file
13
packages/medusa-plugin-twilio-sms/.babelrc
Normal 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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
packages/medusa-plugin-twilio-sms/.eslintrc
Normal file
9
packages/medusa-plugin-twilio-sms/.eslintrc
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["prettier"],
|
||||||
|
"extends": ["prettier"],
|
||||||
|
"rules": {
|
||||||
|
"prettier/prettier": "error",
|
||||||
|
"semi": "error",
|
||||||
|
"no-unused-expressions": "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
packages/medusa-plugin-twilio-sms/.gitignore
vendored
Normal file
15
packages/medusa-plugin-twilio-sms/.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/lib
|
||||||
|
node_modules
|
||||||
|
.DS_store
|
||||||
|
.env*
|
||||||
|
/*.js
|
||||||
|
!index.js
|
||||||
|
!jest.config.js
|
||||||
|
|
||||||
|
/dist
|
||||||
|
|
||||||
|
/api
|
||||||
|
/services
|
||||||
|
/models
|
||||||
|
/subscribers
|
||||||
|
|
||||||
9
packages/medusa-plugin-twilio-sms/.npmignore
Normal file
9
packages/medusa-plugin-twilio-sms/.npmignore
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/lib
|
||||||
|
node_modules
|
||||||
|
.DS_store
|
||||||
|
.env*
|
||||||
|
/*.js
|
||||||
|
!index.js
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
|
|
||||||
7
packages/medusa-plugin-twilio-sms/.prettierrc
Normal file
7
packages/medusa-plugin-twilio-sms/.prettierrc
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"endOfLine": "lf",
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": false,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"trailingComma": "es5"
|
||||||
|
}
|
||||||
24
packages/medusa-plugin-twilio-sms/README.md
Normal file
24
packages/medusa-plugin-twilio-sms/README.md
Normal 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!" })
|
||||||
|
```
|
||||||
1
packages/medusa-plugin-twilio-sms/index.js
Normal file
1
packages/medusa-plugin-twilio-sms/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// noop
|
||||||
3
packages/medusa-plugin-twilio-sms/jest.config.js
Normal file
3
packages/medusa-plugin-twilio-sms/jest.config.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
testEnvironment: "node",
|
||||||
|
}
|
||||||
43
packages/medusa-plugin-twilio-sms/package.json
Normal file
43
packages/medusa-plugin-twilio-sms/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
34
packages/medusa-plugin-twilio-sms/src/services/twilio-sms.js
Normal file
34
packages/medusa-plugin-twilio-sms/src/services/twilio-sms.js
Normal 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
|
||||||
5850
packages/medusa-plugin-twilio-sms/yarn.lock
Normal file
5850
packages/medusa-plugin-twilio-sms/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user