@digipair/skill-twilio 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +49 -0
- package/index.d.ts +1 -0
- package/index.esm.js +44 -0
- package/libs/skill-twilio/src/index.d.ts +1 -0
- package/libs/skill-twilio/src/lib/skill-twilio.d.ts +3 -0
- package/package.json +7 -0
- package/schema.json +142 -0
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _extends() {
|
|
6
|
+
_extends = Object.assign || function assign(target) {
|
|
7
|
+
for(var i = 1; i < arguments.length; i++){
|
|
8
|
+
var source = arguments[i];
|
|
9
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
10
|
+
}
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
return _extends.apply(this, arguments);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let TwilioService = class TwilioService {
|
|
17
|
+
async call(url, method, data, headers) {
|
|
18
|
+
const response = await fetch(`${this.API_ENDPOINT}${url}`, {
|
|
19
|
+
method,
|
|
20
|
+
headers: _extends({
|
|
21
|
+
Authorization: 'Basic ' + btoa(this.TWILIO_SID + ':' + this.TWILIO_TOKEN)
|
|
22
|
+
}, headers),
|
|
23
|
+
body: data
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) throw new Error('[SKILL-TWILIO] REQUEST FAILED: ' + response.status);
|
|
26
|
+
return await response.json();
|
|
27
|
+
}
|
|
28
|
+
async sendSms(params, _pinsSettingsList, _context, whatsapp = false) {
|
|
29
|
+
const { message, phoneNumber } = params;
|
|
30
|
+
return await this.call(`/Accounts/${this.TWILIO_SID}/Messages.json`, 'POST', `From=${encodeURIComponent(`${whatsapp ? 'whatsapp:' : ''}${this.FROM_NUMBER}`)}&Body=${encodeURIComponent(message)}&To=${encodeURIComponent(`${whatsapp ? 'whatsapp:' : ''}${phoneNumber}`)}`, {
|
|
31
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
constructor(context, params){
|
|
35
|
+
var _context_private_TWILIO_SID, _ref;
|
|
36
|
+
this.TWILIO_SID = (_ref = (_context_private_TWILIO_SID = context.private.TWILIO_SID) != null ? _context_private_TWILIO_SID : params == null ? void 0 : params.TWILIO_SID) != null ? _ref : process.env['TWILIO_SID'];
|
|
37
|
+
var _context_private_TWILIO_TOKEN, _ref1;
|
|
38
|
+
this.TWILIO_TOKEN = (_ref1 = (_context_private_TWILIO_TOKEN = context.private.TWILIO_TOKEN) != null ? _context_private_TWILIO_TOKEN : params == null ? void 0 : params.TWILIO_TOKEN) != null ? _ref1 : process.env['TWILIO_TOKEN'];
|
|
39
|
+
var _context_private_TWILIO_FROM_NUMBER, _ref2;
|
|
40
|
+
this.FROM_NUMBER = (_ref2 = (_context_private_TWILIO_FROM_NUMBER = context.private.TWILIO_FROM_NUMBER) != null ? _context_private_TWILIO_FROM_NUMBER : params == null ? void 0 : params.TWILIO_FROM_NUMBER) != null ? _ref2 : process.env['TWILIO_FROM_NUMBER'];
|
|
41
|
+
var _context_private_TWILIO_API_ENDPOINT, _ref3, _ref4;
|
|
42
|
+
this.API_ENDPOINT = (_ref4 = (_ref3 = (_context_private_TWILIO_API_ENDPOINT = context.private.TWILIO_API_ENDPOINT) != null ? _context_private_TWILIO_API_ENDPOINT : params == null ? void 0 : params.TWILIO_API_ENDPOINT) != null ? _ref3 : process.env['TWILIO_API_ENDPOINT']) != null ? _ref4 : 'https://api.twilio.com/2010-04-01';
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const sendSms = (params, pinsSettingsList, context)=>new TwilioService(context, params).sendSms(params, pinsSettingsList, context);
|
|
46
|
+
const sendWhatsapp = (params, pinsSettingsList, context)=>new TwilioService(context, params).sendSms(params, pinsSettingsList, context, true);
|
|
47
|
+
|
|
48
|
+
exports.sendSms = sendSms;
|
|
49
|
+
exports.sendWhatsapp = sendWhatsapp;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './libs/skill-twilio/src/index';
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function assign(target) {
|
|
3
|
+
for(var i = 1; i < arguments.length; i++){
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
6
|
+
}
|
|
7
|
+
return target;
|
|
8
|
+
};
|
|
9
|
+
return _extends.apply(this, arguments);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let TwilioService = class TwilioService {
|
|
13
|
+
async call(url, method, data, headers) {
|
|
14
|
+
const response = await fetch(`${this.API_ENDPOINT}${url}`, {
|
|
15
|
+
method,
|
|
16
|
+
headers: _extends({
|
|
17
|
+
Authorization: 'Basic ' + btoa(this.TWILIO_SID + ':' + this.TWILIO_TOKEN)
|
|
18
|
+
}, headers),
|
|
19
|
+
body: data
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) throw new Error('[SKILL-TWILIO] REQUEST FAILED: ' + response.status);
|
|
22
|
+
return await response.json();
|
|
23
|
+
}
|
|
24
|
+
async sendSms(params, _pinsSettingsList, _context, whatsapp = false) {
|
|
25
|
+
const { message, phoneNumber } = params;
|
|
26
|
+
return await this.call(`/Accounts/${this.TWILIO_SID}/Messages.json`, 'POST', `From=${encodeURIComponent(`${whatsapp ? 'whatsapp:' : ''}${this.FROM_NUMBER}`)}&Body=${encodeURIComponent(message)}&To=${encodeURIComponent(`${whatsapp ? 'whatsapp:' : ''}${phoneNumber}`)}`, {
|
|
27
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
constructor(context, params){
|
|
31
|
+
var _context_private_TWILIO_SID, _ref;
|
|
32
|
+
this.TWILIO_SID = (_ref = (_context_private_TWILIO_SID = context.private.TWILIO_SID) != null ? _context_private_TWILIO_SID : params == null ? void 0 : params.TWILIO_SID) != null ? _ref : process.env['TWILIO_SID'];
|
|
33
|
+
var _context_private_TWILIO_TOKEN, _ref1;
|
|
34
|
+
this.TWILIO_TOKEN = (_ref1 = (_context_private_TWILIO_TOKEN = context.private.TWILIO_TOKEN) != null ? _context_private_TWILIO_TOKEN : params == null ? void 0 : params.TWILIO_TOKEN) != null ? _ref1 : process.env['TWILIO_TOKEN'];
|
|
35
|
+
var _context_private_TWILIO_FROM_NUMBER, _ref2;
|
|
36
|
+
this.FROM_NUMBER = (_ref2 = (_context_private_TWILIO_FROM_NUMBER = context.private.TWILIO_FROM_NUMBER) != null ? _context_private_TWILIO_FROM_NUMBER : params == null ? void 0 : params.TWILIO_FROM_NUMBER) != null ? _ref2 : process.env['TWILIO_FROM_NUMBER'];
|
|
37
|
+
var _context_private_TWILIO_API_ENDPOINT, _ref3, _ref4;
|
|
38
|
+
this.API_ENDPOINT = (_ref4 = (_ref3 = (_context_private_TWILIO_API_ENDPOINT = context.private.TWILIO_API_ENDPOINT) != null ? _context_private_TWILIO_API_ENDPOINT : params == null ? void 0 : params.TWILIO_API_ENDPOINT) != null ? _ref3 : process.env['TWILIO_API_ENDPOINT']) != null ? _ref4 : 'https://api.twilio.com/2010-04-01';
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const sendSms = (params, pinsSettingsList, context)=>new TwilioService(context, params).sendSms(params, pinsSettingsList, context);
|
|
42
|
+
const sendWhatsapp = (params, pinsSettingsList, context)=>new TwilioService(context, params).sendSms(params, pinsSettingsList, context, true);
|
|
43
|
+
|
|
44
|
+
export { sendSms, sendWhatsapp };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/skill-twilio';
|
package/package.json
ADDED
package/schema.json
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "@digipair/skill-twilio",
|
|
5
|
+
"summary": "Gestion des communications via Twilio",
|
|
6
|
+
"description": "Cette compétence permet d'utiliser le service Twilio",
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"x-icon": "🏡"
|
|
9
|
+
},
|
|
10
|
+
"paths": {
|
|
11
|
+
"/sendSms": {
|
|
12
|
+
"post": {
|
|
13
|
+
"tags": ["service"],
|
|
14
|
+
"summary": "Envoie d'un sms via Twilio",
|
|
15
|
+
"parameters": [
|
|
16
|
+
{
|
|
17
|
+
"name": "message",
|
|
18
|
+
"summary": "Message Ă envoyer",
|
|
19
|
+
"required": true,
|
|
20
|
+
"description": "Message Ă envoyer par sms",
|
|
21
|
+
"schema": {
|
|
22
|
+
"type": "string"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "phoneNumber",
|
|
27
|
+
"summary": "Numéro de téléphone",
|
|
28
|
+
"required": true,
|
|
29
|
+
"description": "Numéro de téléphone du destinataire",
|
|
30
|
+
"schema": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "TWILIO_FROM_NUMBER",
|
|
36
|
+
"summary": "Numéro Twilio",
|
|
37
|
+
"required": false,
|
|
38
|
+
"description": "Numéro Twilio",
|
|
39
|
+
"schema": {
|
|
40
|
+
"type": "string"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "TWILIO_SID",
|
|
45
|
+
"summary": "Identifiant Twilio",
|
|
46
|
+
"required": false,
|
|
47
|
+
"description": "Identifiant Twilio",
|
|
48
|
+
"schema": {
|
|
49
|
+
"type": "string"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "TWILIO_TOKEN",
|
|
54
|
+
"summary": "Clé d'API",
|
|
55
|
+
"required": false,
|
|
56
|
+
"description": "Clé d'API Twilio",
|
|
57
|
+
"schema": {
|
|
58
|
+
"type": "string"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "TWILIO_API_ENDPOINT",
|
|
63
|
+
"summary": "Endpoint de l'API",
|
|
64
|
+
"required": false,
|
|
65
|
+
"description": "Endpoint de l'API Twilio",
|
|
66
|
+
"schema": {
|
|
67
|
+
"type": "string"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"x-events": []
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"/sendWhatsapp": {
|
|
75
|
+
"post": {
|
|
76
|
+
"tags": ["service"],
|
|
77
|
+
"summary": "Envoie d'un Whatsapp via Twilio",
|
|
78
|
+
"parameters": [
|
|
79
|
+
{
|
|
80
|
+
"name": "message",
|
|
81
|
+
"summary": "Message Ă envoyer",
|
|
82
|
+
"required": true,
|
|
83
|
+
"description": "Message Ă envoyer par sms",
|
|
84
|
+
"schema": {
|
|
85
|
+
"type": "string"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "phoneNumber",
|
|
90
|
+
"summary": "Numéro de téléphone",
|
|
91
|
+
"required": true,
|
|
92
|
+
"description": "Numéro de téléphone du destinataire",
|
|
93
|
+
"schema": {
|
|
94
|
+
"type": "string"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "TWILIO_FROM_NUMBER",
|
|
99
|
+
"summary": "Numéro Twilio",
|
|
100
|
+
"required": false,
|
|
101
|
+
"description": "Numéro Twilio",
|
|
102
|
+
"schema": {
|
|
103
|
+
"type": "string"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "TWILIO_SID",
|
|
108
|
+
"summary": "Identifiant Twilio",
|
|
109
|
+
"required": false,
|
|
110
|
+
"description": "Identifiant Twilio",
|
|
111
|
+
"schema": {
|
|
112
|
+
"type": "string"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "TWILIO_TOKEN",
|
|
117
|
+
"summary": "Clé d'API",
|
|
118
|
+
"required": false,
|
|
119
|
+
"description": "Clé d'API Twilio",
|
|
120
|
+
"schema": {
|
|
121
|
+
"type": "string"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "TWILIO_API_ENDPOINT",
|
|
126
|
+
"summary": "Endpoint de l'API",
|
|
127
|
+
"required": false,
|
|
128
|
+
"description": "Endpoint de l'API Twilio",
|
|
129
|
+
"schema": {
|
|
130
|
+
"type": "string"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"x-events": []
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
"components": {
|
|
139
|
+
"schemas": {}
|
|
140
|
+
},
|
|
141
|
+
"x-scene-blocks": {}
|
|
142
|
+
}
|