@ingestkorea/client-sens 1.4.3 → 1.5.2
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/README.md +42 -10
- package/dist-cjs/commands/SendAlimtalkCommand.js +3 -3
- package/dist-cjs/commands/SendMMSCommand.js +115 -0
- package/dist-cjs/commands/SendSMSCommand.js +32 -31
- package/dist-cjs/commands/constants.js +20 -0
- package/dist-cjs/commands/index.js +1 -0
- package/dist-cjs/middleware/metadata-ingestkorea.js +1 -1
- package/dist-cjs/models/SendMMS.js +4 -0
- package/dist-cjs/models/index.js +1 -0
- package/dist-cjs/protocols/GetSMSResult.js +1 -1
- package/dist-cjs/protocols/GetSMSStatus.js +1 -1
- package/dist-cjs/protocols/SendMMS.js +51 -0
- package/dist-cjs/protocols/SendSMS.js +1 -1
- package/dist-cjs/protocols/index.js +1 -0
- package/dist-es/commands/SendAlimtalkCommand.js +3 -3
- package/dist-es/commands/SendMMSCommand.js +109 -0
- package/dist-es/commands/SendSMSCommand.js +36 -35
- package/dist-es/commands/constants.js +14 -0
- package/dist-es/commands/index.js +1 -0
- package/dist-es/middleware/metadata-ingestkorea.js +1 -1
- package/dist-es/models/SendMMS.js +3 -0
- package/dist-es/models/index.js +1 -0
- package/dist-es/protocols/GetSMSResult.js +1 -1
- package/dist-es/protocols/GetSMSStatus.js +1 -1
- package/dist-es/protocols/SendMMS.js +47 -0
- package/dist-es/protocols/SendSMS.js +1 -1
- package/dist-es/protocols/index.js +1 -0
- package/dist-types/commands/SendMMSCommand.d.ts +13 -0
- package/dist-types/commands/constants.d.ts +7 -0
- package/dist-types/commands/index.d.ts +1 -0
- package/dist-types/models/SendMMS.d.ts +10 -0
- package/dist-types/models/SendSMS.d.ts +1 -1
- package/dist-types/models/index.d.ts +1 -0
- package/dist-types/protocols/SendMMS.d.ts +7 -0
- package/dist-types/protocols/index.d.ts +1 -0
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @ingestkorea/client-sens
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@ingestkorea/client-sens)
|
|
4
|
-
[](https://www.npmjs.com/package/@ingestkorea/client-sens)
|
|
5
|
+

|
|
6
6
|
|
|
7
7
|
## Description
|
|
8
8
|
INGESTKOREA SDK Naver Cloud Platform SENS Client for Node.js.
|
|
@@ -31,10 +31,11 @@ npm install @ingestkorea/client-sens
|
|
|
31
31
|
+ ListAlimtalkTemplates (`ListTemplates` is deprecated)
|
|
32
32
|
+ ListAlimtalkChannels (`ListChannels` is deprecated)
|
|
33
33
|
|
|
34
|
-
#### SMS
|
|
35
|
-
+ SendSMS
|
|
36
|
-
+
|
|
37
|
-
+
|
|
34
|
+
#### SMS, LMS, MMS
|
|
35
|
+
+ SendSMS (SMS, LMS)
|
|
36
|
+
+ SendMMS (MMS)
|
|
37
|
+
+ GetSMSStatus (SMS, LMS, MMS)
|
|
38
|
+
+ GetSMSResult (SMS, LMS, MMS)
|
|
38
39
|
|
|
39
40
|
### Import
|
|
40
41
|
```ts
|
|
@@ -42,6 +43,7 @@ import {
|
|
|
42
43
|
SensClient,
|
|
43
44
|
SendAlimtalkCommand, SendAlimtalkCommandInput,
|
|
44
45
|
SendSMSCommand, SendSMSCommandInput,
|
|
46
|
+
SendMMSCommand, SendMMSCommandInput,
|
|
45
47
|
} from '@ingestkorea/client-sens';
|
|
46
48
|
```
|
|
47
49
|
|
|
@@ -85,7 +87,7 @@ let params: SendAlimtalkCommandInput = {
|
|
|
85
87
|
let command = new SendAlimtalkCommand(params);
|
|
86
88
|
```
|
|
87
89
|
|
|
88
|
-
#### SendSMS
|
|
90
|
+
#### SendSMS (SMS, LMS)
|
|
89
91
|
```ts
|
|
90
92
|
/**
|
|
91
93
|
* Automatically set message type('SMS' | 'LMS') according to content-length(euc-kr)
|
|
@@ -96,13 +98,43 @@ let params: SendSMSCommandInput = {
|
|
|
96
98
|
from: '01012345678',
|
|
97
99
|
content: DEFAULT_CONTENT,
|
|
98
100
|
messages: [
|
|
101
|
+
{ to: '0109182xxxx' },
|
|
102
|
+
{ to: '0104321xxxx', content?: OPTIONAL_CONTENT_01 }
|
|
103
|
+
{ to: '0108765xxxx', content?: OPTIONAL_CONTENT_02, subject?: OPTIONAL_SUBJECT_01 },
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* If you do not define the subject and content within the messages,
|
|
108
|
+
* it is sent with the value specified as the default subject('제목없음') and content.
|
|
109
|
+
*/
|
|
110
|
+
let command = new SendSMSCommand(params);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### SendMMS (MMS)
|
|
114
|
+
```ts
|
|
115
|
+
import { readFileSync } from 'node:fs';
|
|
116
|
+
|
|
117
|
+
let params: SendMMSCommandInput = {
|
|
118
|
+
from: '01012345678',
|
|
119
|
+
content: DEFAULT_CONTENT,
|
|
120
|
+
messages: [
|
|
121
|
+
{ to: '0109182xxxx' },
|
|
122
|
+
{ to: '0104321xxxx', content?: OPTIONAL_CONTENT_01 }
|
|
123
|
+
{ to: '0108765xxxx', content?: OPTIONAL_CONTENT_02, subject?: OPTIONAL_SUBJECT_01 },
|
|
124
|
+
],
|
|
125
|
+
files: [ // support jpg, jpeg
|
|
126
|
+
{ name: '/your/absolute/path/sample-image-1.jpg' },
|
|
99
127
|
{
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
name: '/your/absolute/path/sample-image-2.jpg',
|
|
129
|
+
body?: readFileSync('/your/absolute/path/sample-image-2.jpg', { encoding: 'base64' })
|
|
102
130
|
}
|
|
103
131
|
]
|
|
104
132
|
};
|
|
105
|
-
|
|
133
|
+
/**
|
|
134
|
+
* If you do not define the subject and content within the messages,
|
|
135
|
+
* it is sent with the value specified as the default subject('제목없음') and content.
|
|
136
|
+
*/
|
|
137
|
+
let command = new SendMMSCommand(params);
|
|
106
138
|
```
|
|
107
139
|
|
|
108
140
|
#### Async/await
|
|
@@ -43,11 +43,11 @@ class SendAlimtalkCommand extends models_1.SensCommand {
|
|
|
43
43
|
exports.SendAlimtalkCommand = SendAlimtalkCommand;
|
|
44
44
|
;
|
|
45
45
|
const resolveAlimtalkMessage = (message) => {
|
|
46
|
-
const
|
|
47
|
-
if (message.content.length >
|
|
46
|
+
const ALIMTALK_MAX = 1000;
|
|
47
|
+
if (message.content.length > ALIMTALK_MAX)
|
|
48
48
|
throw new util_error_handler_1.IngestkoreaError({
|
|
49
49
|
code: 400, type: 'Bad Request',
|
|
50
|
-
message: 'Invalid Params', description: `Maximum message length is ${
|
|
50
|
+
message: 'Invalid Params', description: `Maximum message length is ${ALIMTALK_MAX}`
|
|
51
51
|
});
|
|
52
52
|
return Object.assign({ to: message.to.replace(/\-/gi, ""), content: message.content }, (message.buttons != undefined && { buttons: message.buttons }));
|
|
53
53
|
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SendMMSCommand = void 0;
|
|
13
|
+
const models_1 = require("../models");
|
|
14
|
+
const SendMMS_1 = require("../protocols/SendMMS");
|
|
15
|
+
const util_error_handler_1 = require("@ingestkorea/util-error-handler");
|
|
16
|
+
const constants_1 = require("./constants");
|
|
17
|
+
const node_path_1 = require("node:path");
|
|
18
|
+
const node_crypto_1 = require("node:crypto");
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
;
|
|
21
|
+
;
|
|
22
|
+
class SendMMSCommand extends models_1.SensCommand {
|
|
23
|
+
constructor(input) {
|
|
24
|
+
super(input);
|
|
25
|
+
this.input = Object.assign(Object.assign({}, input), { from: (0, constants_1.prettyPhoneNum)(input.from), content: resolveInputContent(input.content), type: resolveInputMessageType(input.type), messages: resolveInputMessages(input.messages), files: resolveInputFiles(input.files) });
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
serialize(input, config) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (!config.serviceId.sms)
|
|
31
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
32
|
+
code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
|
|
33
|
+
});
|
|
34
|
+
let request = yield (0, SendMMS_1.serializeIngestkorea_restJson_SendMMSCommand)(input, config);
|
|
35
|
+
return request;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
;
|
|
39
|
+
deserialize(response) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
let output = yield (0, SendMMS_1.deserializeIngestkorea_restJson_SendMMSCommand)(response);
|
|
42
|
+
return output;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
;
|
|
46
|
+
}
|
|
47
|
+
exports.SendMMSCommand = SendMMSCommand;
|
|
48
|
+
;
|
|
49
|
+
const resolveInputContent = (content) => {
|
|
50
|
+
const resolvedContent = (0, constants_1.trimText)(content);
|
|
51
|
+
const contentLength = (0, constants_1.getContentLength)(resolvedContent);
|
|
52
|
+
if (!contentLength)
|
|
53
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
54
|
+
code: 400, type: 'Bad Request',
|
|
55
|
+
message: 'Invalid Request', description: `Please check input message`
|
|
56
|
+
});
|
|
57
|
+
if (contentLength > constants_1.LMS_MAX)
|
|
58
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
59
|
+
code: 400, type: 'Bad Request',
|
|
60
|
+
message: 'Invalid Request', description: `Maximum message length is ${constants_1.LMS_MAX}bytes`
|
|
61
|
+
});
|
|
62
|
+
return resolvedContent;
|
|
63
|
+
};
|
|
64
|
+
const resolveInputMessages = (messages) => messages.map(message => {
|
|
65
|
+
return Object.assign(Object.assign({ to: (0, constants_1.prettyPhoneNum)(message.to) }, (message.content != undefined && { content: resolveInputContent(message.content) })), (message.subject != undefined && { subject: (0, constants_1.trimText)(message.subject) }));
|
|
66
|
+
});
|
|
67
|
+
const resolveInputMessageType = (type) => {
|
|
68
|
+
if (type == 'SMS' || type == 'LMS')
|
|
69
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
70
|
+
code: 400, type: 'Bad Request',
|
|
71
|
+
message: 'Invalid Request', description: `Please Call SendSMSCommand`
|
|
72
|
+
});
|
|
73
|
+
return 'MMS';
|
|
74
|
+
};
|
|
75
|
+
const resolveInputFiles = (files) => {
|
|
76
|
+
if (!files.length)
|
|
77
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
78
|
+
code: 400, type: 'Bad Request',
|
|
79
|
+
message: 'Invalid Request', description: `Please Check Input Files`
|
|
80
|
+
});
|
|
81
|
+
const output = files.map(file => {
|
|
82
|
+
const resolvedFileName = verifyFileName(file.name);
|
|
83
|
+
const resolvedFileBody = file.body != undefined ? file.body : getFileBody(file.name);
|
|
84
|
+
let byte = Buffer.from(resolvedFileBody, 'base64').length;
|
|
85
|
+
let kib = Math.ceil(byte / 1024);
|
|
86
|
+
if (kib > constants_1.MMS_FILE_MAX)
|
|
87
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
88
|
+
code: 400, type: 'Bad Request',
|
|
89
|
+
message: 'Invalid Request',
|
|
90
|
+
description: `Input File is ${kib}KiByte. Maximum File Size is ${constants_1.MMS_FILE_MAX}Kibyte`
|
|
91
|
+
});
|
|
92
|
+
return { name: resolvedFileName, body: resolvedFileBody };
|
|
93
|
+
});
|
|
94
|
+
return output;
|
|
95
|
+
};
|
|
96
|
+
const verifyFileName = (fileName) => {
|
|
97
|
+
let { ext } = (0, node_path_1.parse)(fileName);
|
|
98
|
+
const uuid = (0, node_crypto_1.randomUUID)();
|
|
99
|
+
const extension = ext.replace(/jpeg|jpg/gi, "jpg");
|
|
100
|
+
if (extension != '.jpg')
|
|
101
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
102
|
+
code: 400, type: 'Bad Request',
|
|
103
|
+
message: 'Invalid Request', description: `File Extension is not .jpg or .jpeg`
|
|
104
|
+
});
|
|
105
|
+
return [uuid, extension].join('');
|
|
106
|
+
};
|
|
107
|
+
/** @returns base64 */
|
|
108
|
+
const getFileBody = (fileName) => {
|
|
109
|
+
if (!(0, node_fs_1.existsSync)(fileName))
|
|
110
|
+
throw new util_error_handler_1.IngestkoreaError({
|
|
111
|
+
code: 400, type: 'Bad Request',
|
|
112
|
+
message: 'Invalid Request', description: `${fileName} does not exist.`
|
|
113
|
+
});
|
|
114
|
+
return (0, node_fs_1.readFileSync)(fileName, { encoding: 'base64' });
|
|
115
|
+
};
|
|
@@ -13,15 +13,15 @@ exports.SendSMSCommand = void 0;
|
|
|
13
13
|
const models_1 = require("../models");
|
|
14
14
|
const SendSMS_1 = require("../protocols/SendSMS");
|
|
15
15
|
const util_error_handler_1 = require("@ingestkorea/util-error-handler");
|
|
16
|
+
const constants_1 = require("./constants");
|
|
16
17
|
;
|
|
17
18
|
;
|
|
18
19
|
class SendSMSCommand extends models_1.SensCommand {
|
|
19
20
|
constructor(input) {
|
|
20
21
|
super(input);
|
|
21
|
-
const content =
|
|
22
|
+
const { content, messageType: defaultMessageType } = resolveInputContent(input.content);
|
|
22
23
|
const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
|
|
23
|
-
|
|
24
|
-
this.input = Object.assign(Object.assign({}, input), { from: prettyPhoneNum(input.from), content: content, type: messageType, messages: messages });
|
|
24
|
+
this.input = Object.assign(Object.assign({}, input), { from: (0, constants_1.prettyPhoneNum)(input.from), content: content, type: defaultMessageType === childMessageType ? defaultMessageType : 'LMS', messages: messages });
|
|
25
25
|
}
|
|
26
26
|
;
|
|
27
27
|
serialize(input, config) {
|
|
@@ -45,41 +45,42 @@ class SendSMSCommand extends models_1.SensCommand {
|
|
|
45
45
|
}
|
|
46
46
|
exports.SendSMSCommand = SendSMSCommand;
|
|
47
47
|
;
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
return input.split('').reduce((acc, text) => {
|
|
52
|
-
let byte = Buffer.from(text).length;
|
|
53
|
-
let modulo = byte % 3;
|
|
54
|
-
modulo ? acc += 1 : acc += 2;
|
|
55
|
-
return acc;
|
|
56
|
-
}, 0);
|
|
57
|
-
};
|
|
58
|
-
const checkMessageType = (input) => {
|
|
59
|
-
const SMS_MAX = 90;
|
|
60
|
-
const LMS_MAX = 2000;
|
|
61
|
-
const euckrBytes = getTextBytes(input);
|
|
62
|
-
if (!euckrBytes)
|
|
48
|
+
const getMessageType = (input) => {
|
|
49
|
+
const contentLength = (0, constants_1.getContentLength)(input);
|
|
50
|
+
if (!contentLength)
|
|
63
51
|
throw new util_error_handler_1.IngestkoreaError({
|
|
64
52
|
code: 400, type: 'Bad Request',
|
|
65
53
|
message: 'Invalid Request', description: `Please check input message`
|
|
66
54
|
});
|
|
67
|
-
if (
|
|
55
|
+
if (contentLength > constants_1.LMS_MAX)
|
|
68
56
|
throw new util_error_handler_1.IngestkoreaError({
|
|
69
57
|
code: 400, type: 'Bad Request',
|
|
70
|
-
message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
|
|
58
|
+
message: 'Invalid Request', description: `Maximum message length is ${constants_1.LMS_MAX}bytes`
|
|
71
59
|
});
|
|
72
|
-
return
|
|
60
|
+
return contentLength > constants_1.SMS_MAX ? 'LMS' : 'SMS';
|
|
61
|
+
};
|
|
62
|
+
const resolveInputContent = (content) => {
|
|
63
|
+
const resolvedContent = (0, constants_1.trimText)(content);
|
|
64
|
+
const messageType = getMessageType(resolvedContent);
|
|
65
|
+
return {
|
|
66
|
+
content: resolvedContent,
|
|
67
|
+
messageType: messageType
|
|
68
|
+
};
|
|
73
69
|
};
|
|
74
70
|
const resolveInputMessages = (messages) => {
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
let init = {
|
|
72
|
+
messages: [],
|
|
73
|
+
messageType: 'SMS'
|
|
74
|
+
};
|
|
75
|
+
const output = messages.reduce((acc, message) => {
|
|
76
|
+
const to = (0, constants_1.prettyPhoneNum)(message.to);
|
|
77
|
+
const content = message.content != undefined ? (0, constants_1.trimText)(message.content) : undefined;
|
|
78
|
+
const subject = message.subject != undefined ? (0, constants_1.trimText)(message.subject) : undefined;
|
|
79
|
+
const messageType = content != undefined ? getMessageType(content) : 'SMS';
|
|
80
|
+
if (messageType == 'LMS')
|
|
81
|
+
acc.messageType = messageType;
|
|
82
|
+
acc.messages.push(Object.assign(Object.assign({ to: to }, (content != undefined && { content: content })), (subject != undefined && acc.messageType === 'LMS' && { subject: subject })));
|
|
83
|
+
return acc;
|
|
84
|
+
}, init);
|
|
85
|
+
return output;
|
|
85
86
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentLength = exports.prettyPhoneNum = exports.trimText = exports.MMS_FILE_MAX = exports.LMS_MAX = exports.SMS_MAX = void 0;
|
|
4
|
+
exports.SMS_MAX = 90;
|
|
5
|
+
exports.LMS_MAX = 2000;
|
|
6
|
+
exports.MMS_FILE_MAX = 300; // KiByte
|
|
7
|
+
const trimText = (input) => input.trim();
|
|
8
|
+
exports.trimText = trimText;
|
|
9
|
+
const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
|
|
10
|
+
exports.prettyPhoneNum = prettyPhoneNum;
|
|
11
|
+
/** @returns content-length(euc-kr) */
|
|
12
|
+
const getContentLength = (input) => {
|
|
13
|
+
return input.split('').reduce((acc, text) => {
|
|
14
|
+
let byte = Buffer.from(text).length;
|
|
15
|
+
let modulo = byte % 3;
|
|
16
|
+
modulo ? acc += 1 : acc += 2;
|
|
17
|
+
return acc;
|
|
18
|
+
}, 0);
|
|
19
|
+
};
|
|
20
|
+
exports.getContentLength = getContentLength;
|
|
@@ -21,5 +21,6 @@ __exportStar(require("./GetAlimtalkTemplateCommand"), exports);
|
|
|
21
21
|
__exportStar(require("./ListAlimtalkTemplatesCommand"), exports);
|
|
22
22
|
__exportStar(require("./ListAlimtalkChannelsCommand"), exports);
|
|
23
23
|
__exportStar(require("./SendSMSCommand"), exports);
|
|
24
|
+
__exportStar(require("./SendMMSCommand"), exports);
|
|
24
25
|
__exportStar(require("./GetSMSStatusCommand"), exports);
|
|
25
26
|
__exportStar(require("./GetSMSResultCommand"), exports);
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.middlewareIngestkoreaMetadata = void 0;
|
|
13
13
|
const middlewareIngestkoreaMetadata = (request, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
14
|
const { longDate } = yield convertFormatDate(request.headers['x-ncp-apigw-timestamp']);
|
|
15
|
-
request.headers = Object.assign(Object.assign({}, request.headers), { ['x-ingestkorea-date']: longDate, ['x-ingestkorea-user-agent']: '@ingestkorea/client-sens/1.
|
|
15
|
+
request.headers = Object.assign(Object.assign({}, request.headers), { ['x-ingestkorea-date']: longDate, ['x-ingestkorea-user-agent']: '@ingestkorea/client-sens/1.5.x' });
|
|
16
16
|
return request;
|
|
17
17
|
});
|
|
18
18
|
exports.middlewareIngestkoreaMetadata = middlewareIngestkoreaMetadata;
|
package/dist-cjs/models/index.js
CHANGED
|
@@ -22,5 +22,6 @@ __exportStar(require("./GetAlimtalkTemplate"), exports);
|
|
|
22
22
|
__exportStar(require("./ListAlimtalkTemplates"), exports);
|
|
23
23
|
__exportStar(require("./ListAlimtalkChannels"), exports);
|
|
24
24
|
__exportStar(require("./SendSMS"), exports);
|
|
25
|
+
__exportStar(require("./SendMMS"), exports);
|
|
25
26
|
__exportStar(require("./GetSMSStatus"), exports);
|
|
26
27
|
__exportStar(require("./GetSMSResult"), exports);
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.deserializeIngestkorea_restJson_File = exports.deserializeIngestkorea_restJson_SMSResultMessage = exports.deserializeIngestkorea_restJson_GetSMSResultOutput = exports.deserializeIngestkorea_restJson_GetSMSResultCommand = exports.serializeIngestkorea_restJson_GetSMSResultCommand = void 0;
|
|
13
13
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
|
-
const constants_1 = require("
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
15
|
const serializeIngestkorea_restJson_GetSMSResultCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const hostname = "sens.apigw.ntruss.com";
|
|
17
17
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages" + '/' + input.messageId;
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.deserializeIngestkorea_restJson_SMSStatusMessage = exports.deserializeIngestkorea_restJson_GetSMSStatusOutput = exports.deserializeIngestkorea_restJson_GetSMSStatusCommand = exports.serializeIngestkorea_restJson_GetSMSStatusCommand = void 0;
|
|
13
13
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
|
-
const constants_1 = require("
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
15
|
const serializeIngestkorea_restJson_GetSMSStatusCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const hostname = "sens.apigw.ntruss.com";
|
|
17
17
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.deserializeIngestkorea_restJson_SendMMSOutput = exports.deserializeIngestkorea_restJson_SendMMSCommand = exports.serializeIngestkorea_restJson_SendMMSCommand = void 0;
|
|
13
|
+
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const serializeIngestkorea_restJson_SendMMSCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const hostname = "sens.apigw.ntruss.com";
|
|
17
|
+
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
18
|
+
const headers = {
|
|
19
|
+
"content-type": "application/json; charset=utf-8",
|
|
20
|
+
"host": hostname
|
|
21
|
+
};
|
|
22
|
+
const body = JSON.stringify(Object.assign(Object.assign(Object.assign({ from: input.from, content: input.content, messages: input.messages, type: input.type != undefined ? input.type : 'MMS', files: input.files }, (input.contentType != undefined && { contentType: input.contentType })), (input.countryCode != undefined && { countryCode: input.countryCode })), (input.subject != undefined && { subject: input.subject })));
|
|
23
|
+
return new util_http_handler_1.HttpRequest({
|
|
24
|
+
protocol: 'https:',
|
|
25
|
+
method: 'POST',
|
|
26
|
+
hostname: hostname,
|
|
27
|
+
path: path,
|
|
28
|
+
headers: headers,
|
|
29
|
+
body: body
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
exports.serializeIngestkorea_restJson_SendMMSCommand = serializeIngestkorea_restJson_SendMMSCommand;
|
|
33
|
+
const deserializeIngestkorea_restJson_SendMMSCommand = (output) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
if (output.statusCode > 300)
|
|
35
|
+
yield (0, constants_1.parseErrorBody)(output);
|
|
36
|
+
const data = yield (0, constants_1.parseBody)(output); // SendSMSOutput
|
|
37
|
+
let contents = {};
|
|
38
|
+
contents = yield (0, exports.deserializeIngestkorea_restJson_SendMMSOutput)(data);
|
|
39
|
+
const response = Object.assign({}, contents);
|
|
40
|
+
return response;
|
|
41
|
+
});
|
|
42
|
+
exports.deserializeIngestkorea_restJson_SendMMSCommand = deserializeIngestkorea_restJson_SendMMSCommand;
|
|
43
|
+
const deserializeIngestkorea_restJson_SendMMSOutput = (output) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
return {
|
|
45
|
+
requestId: output.requestId ? output.requestId : undefined,
|
|
46
|
+
requestTime: output.requestTime ? output.requestTime : undefined,
|
|
47
|
+
statusCode: output.statusCode ? output.statusCode : undefined,
|
|
48
|
+
statusName: output.statusName ? output.statusName : undefined,
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
exports.deserializeIngestkorea_restJson_SendMMSOutput = deserializeIngestkorea_restJson_SendMMSOutput;
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.deserializeIngestkorea_restJson_SendSMSOutput = exports.deserializeIngestkorea_restJson_SendSMSCommand = exports.serializeIngestkorea_restJson_SendSMSCommand = void 0;
|
|
13
13
|
const util_http_handler_1 = require("@ingestkorea/util-http-handler");
|
|
14
|
-
const constants_1 = require("
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
15
|
const serializeIngestkorea_restJson_SendSMSCommand = (input, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const hostname = "sens.apigw.ntruss.com";
|
|
17
17
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
@@ -21,5 +21,6 @@ __exportStar(require("./GetAlimtalkTemplate"), exports);
|
|
|
21
21
|
__exportStar(require("./ListAlimtalkTemplates"), exports);
|
|
22
22
|
__exportStar(require("./ListAlimtalkChannels"), exports);
|
|
23
23
|
__exportStar(require("./SendSMS"), exports);
|
|
24
|
+
__exportStar(require("./SendMMS"), exports);
|
|
24
25
|
__exportStar(require("./GetSMSStatus"), exports);
|
|
25
26
|
__exportStar(require("./GetSMSResult"), exports);
|
|
@@ -31,11 +31,11 @@ export class SendAlimtalkCommand extends SensCommand {
|
|
|
31
31
|
}
|
|
32
32
|
;
|
|
33
33
|
const resolveAlimtalkMessage = (message) => {
|
|
34
|
-
const
|
|
35
|
-
if (message.content.length >
|
|
34
|
+
const ALIMTALK_MAX = 1000;
|
|
35
|
+
if (message.content.length > ALIMTALK_MAX)
|
|
36
36
|
throw new IngestkoreaError({
|
|
37
37
|
code: 400, type: 'Bad Request',
|
|
38
|
-
message: 'Invalid Params', description: `Maximum message length is ${
|
|
38
|
+
message: 'Invalid Params', description: `Maximum message length is ${ALIMTALK_MAX}`
|
|
39
39
|
});
|
|
40
40
|
return {
|
|
41
41
|
to: message.to.replace(/\-/gi, ""),
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { SensCommand } from '../models';
|
|
2
|
+
import { serializeIngestkorea_restJson_SendMMSCommand, deserializeIngestkorea_restJson_SendMMSCommand } from '../protocols/SendMMS';
|
|
3
|
+
import { IngestkoreaError } from '@ingestkorea/util-error-handler';
|
|
4
|
+
import { LMS_MAX, MMS_FILE_MAX, trimText, prettyPhoneNum, getContentLength } from './constants';
|
|
5
|
+
import { parse } from 'node:path';
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
8
|
+
;
|
|
9
|
+
;
|
|
10
|
+
export class SendMMSCommand extends SensCommand {
|
|
11
|
+
constructor(input) {
|
|
12
|
+
super(input);
|
|
13
|
+
this.input = {
|
|
14
|
+
...input,
|
|
15
|
+
from: prettyPhoneNum(input.from),
|
|
16
|
+
content: resolveInputContent(input.content),
|
|
17
|
+
type: resolveInputMessageType(input.type),
|
|
18
|
+
messages: resolveInputMessages(input.messages),
|
|
19
|
+
files: resolveInputFiles(input.files)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
;
|
|
23
|
+
async serialize(input, config) {
|
|
24
|
+
if (!config.serviceId.sms)
|
|
25
|
+
throw new IngestkoreaError({
|
|
26
|
+
code: 400, type: 'Bad Request', message: 'Invalid Params', description: 'Please Check SMS ServiceId'
|
|
27
|
+
});
|
|
28
|
+
let request = await serializeIngestkorea_restJson_SendMMSCommand(input, config);
|
|
29
|
+
return request;
|
|
30
|
+
}
|
|
31
|
+
;
|
|
32
|
+
async deserialize(response) {
|
|
33
|
+
let output = await deserializeIngestkorea_restJson_SendMMSCommand(response);
|
|
34
|
+
return output;
|
|
35
|
+
}
|
|
36
|
+
;
|
|
37
|
+
}
|
|
38
|
+
;
|
|
39
|
+
const resolveInputContent = (content) => {
|
|
40
|
+
const resolvedContent = trimText(content);
|
|
41
|
+
const contentLength = getContentLength(resolvedContent);
|
|
42
|
+
if (!contentLength)
|
|
43
|
+
throw new IngestkoreaError({
|
|
44
|
+
code: 400, type: 'Bad Request',
|
|
45
|
+
message: 'Invalid Request', description: `Please check input message`
|
|
46
|
+
});
|
|
47
|
+
if (contentLength > LMS_MAX)
|
|
48
|
+
throw new IngestkoreaError({
|
|
49
|
+
code: 400, type: 'Bad Request',
|
|
50
|
+
message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
|
|
51
|
+
});
|
|
52
|
+
return resolvedContent;
|
|
53
|
+
};
|
|
54
|
+
const resolveInputMessages = (messages) => messages.map(message => {
|
|
55
|
+
return {
|
|
56
|
+
to: prettyPhoneNum(message.to),
|
|
57
|
+
...(message.content != undefined && { content: resolveInputContent(message.content) }),
|
|
58
|
+
...(message.subject != undefined && { subject: trimText(message.subject) }),
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
const resolveInputMessageType = (type) => {
|
|
62
|
+
if (type == 'SMS' || type == 'LMS')
|
|
63
|
+
throw new IngestkoreaError({
|
|
64
|
+
code: 400, type: 'Bad Request',
|
|
65
|
+
message: 'Invalid Request', description: `Please Call SendSMSCommand`
|
|
66
|
+
});
|
|
67
|
+
return 'MMS';
|
|
68
|
+
};
|
|
69
|
+
const resolveInputFiles = (files) => {
|
|
70
|
+
if (!files.length)
|
|
71
|
+
throw new IngestkoreaError({
|
|
72
|
+
code: 400, type: 'Bad Request',
|
|
73
|
+
message: 'Invalid Request', description: `Please Check Input Files`
|
|
74
|
+
});
|
|
75
|
+
const output = files.map(file => {
|
|
76
|
+
const resolvedFileName = verifyFileName(file.name);
|
|
77
|
+
const resolvedFileBody = file.body != undefined ? file.body : getFileBody(file.name);
|
|
78
|
+
let byte = Buffer.from(resolvedFileBody, 'base64').length;
|
|
79
|
+
let kib = Math.ceil(byte / 1024);
|
|
80
|
+
if (kib > MMS_FILE_MAX)
|
|
81
|
+
throw new IngestkoreaError({
|
|
82
|
+
code: 400, type: 'Bad Request',
|
|
83
|
+
message: 'Invalid Request',
|
|
84
|
+
description: `Input File is ${kib}KiByte. Maximum File Size is ${MMS_FILE_MAX}Kibyte`
|
|
85
|
+
});
|
|
86
|
+
return { name: resolvedFileName, body: resolvedFileBody };
|
|
87
|
+
});
|
|
88
|
+
return output;
|
|
89
|
+
};
|
|
90
|
+
const verifyFileName = (fileName) => {
|
|
91
|
+
let { ext } = parse(fileName);
|
|
92
|
+
const uuid = randomUUID();
|
|
93
|
+
const extension = ext.replace(/jpeg|jpg/gi, "jpg");
|
|
94
|
+
if (extension != '.jpg')
|
|
95
|
+
throw new IngestkoreaError({
|
|
96
|
+
code: 400, type: 'Bad Request',
|
|
97
|
+
message: 'Invalid Request', description: `File Extension is not .jpg or .jpeg`
|
|
98
|
+
});
|
|
99
|
+
return [uuid, extension].join('');
|
|
100
|
+
};
|
|
101
|
+
/** @returns base64 */
|
|
102
|
+
const getFileBody = (fileName) => {
|
|
103
|
+
if (!existsSync(fileName))
|
|
104
|
+
throw new IngestkoreaError({
|
|
105
|
+
code: 400, type: 'Bad Request',
|
|
106
|
+
message: 'Invalid Request', description: `${fileName} does not exist.`
|
|
107
|
+
});
|
|
108
|
+
return readFileSync(fileName, { encoding: 'base64' });
|
|
109
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { SensCommand } from '../models';
|
|
2
2
|
import { serializeIngestkorea_restJson_SendSMSCommand, deserializeIngestkorea_restJson_SendSMSCommand } from '../protocols/SendSMS';
|
|
3
3
|
import { IngestkoreaError } from '@ingestkorea/util-error-handler';
|
|
4
|
+
import { SMS_MAX, LMS_MAX, trimText, prettyPhoneNum, getContentLength } from './constants';
|
|
4
5
|
;
|
|
5
6
|
;
|
|
6
7
|
export class SendSMSCommand extends SensCommand {
|
|
7
8
|
constructor(input) {
|
|
8
9
|
super(input);
|
|
9
|
-
const content =
|
|
10
|
+
const { content, messageType: defaultMessageType } = resolveInputContent(input.content);
|
|
10
11
|
const { messages, messageType: childMessageType } = resolveInputMessages(input.messages);
|
|
11
|
-
const messageType = childMessageType == 'LMS' ? childMessageType : checkMessageType(content);
|
|
12
12
|
this.input = {
|
|
13
13
|
...input,
|
|
14
14
|
from: prettyPhoneNum(input.from),
|
|
15
15
|
content: content,
|
|
16
|
-
type:
|
|
17
|
-
messages: messages
|
|
16
|
+
type: defaultMessageType === childMessageType ? defaultMessageType : 'LMS',
|
|
17
|
+
messages: messages,
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
;
|
|
@@ -34,45 +34,46 @@ export class SendSMSCommand extends SensCommand {
|
|
|
34
34
|
;
|
|
35
35
|
}
|
|
36
36
|
;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return input.split('').reduce((acc, text) => {
|
|
41
|
-
let byte = Buffer.from(text).length;
|
|
42
|
-
let modulo = byte % 3;
|
|
43
|
-
modulo ? acc += 1 : acc += 2;
|
|
44
|
-
return acc;
|
|
45
|
-
}, 0);
|
|
46
|
-
};
|
|
47
|
-
const checkMessageType = (input) => {
|
|
48
|
-
const SMS_MAX = 90;
|
|
49
|
-
const LMS_MAX = 2000;
|
|
50
|
-
const euckrBytes = getTextBytes(input);
|
|
51
|
-
if (!euckrBytes)
|
|
37
|
+
const getMessageType = (input) => {
|
|
38
|
+
const contentLength = getContentLength(input);
|
|
39
|
+
if (!contentLength)
|
|
52
40
|
throw new IngestkoreaError({
|
|
53
41
|
code: 400, type: 'Bad Request',
|
|
54
42
|
message: 'Invalid Request', description: `Please check input message`
|
|
55
43
|
});
|
|
56
|
-
if (
|
|
44
|
+
if (contentLength > LMS_MAX)
|
|
57
45
|
throw new IngestkoreaError({
|
|
58
46
|
code: 400, type: 'Bad Request',
|
|
59
47
|
message: 'Invalid Request', description: `Maximum message length is ${LMS_MAX}bytes`
|
|
60
48
|
});
|
|
61
|
-
return
|
|
49
|
+
return contentLength > SMS_MAX ? 'LMS' : 'SMS';
|
|
50
|
+
};
|
|
51
|
+
const resolveInputContent = (content) => {
|
|
52
|
+
const resolvedContent = trimText(content);
|
|
53
|
+
const messageType = getMessageType(resolvedContent);
|
|
54
|
+
return {
|
|
55
|
+
content: resolvedContent,
|
|
56
|
+
messageType: messageType
|
|
57
|
+
};
|
|
62
58
|
};
|
|
63
59
|
const resolveInputMessages = (messages) => {
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
let init = {
|
|
61
|
+
messages: [],
|
|
62
|
+
messageType: 'SMS'
|
|
63
|
+
};
|
|
64
|
+
const output = messages.reduce((acc, message) => {
|
|
65
|
+
const to = prettyPhoneNum(message.to);
|
|
66
|
+
const content = message.content != undefined ? trimText(message.content) : undefined;
|
|
67
|
+
const subject = message.subject != undefined ? trimText(message.subject) : undefined;
|
|
68
|
+
const messageType = content != undefined ? getMessageType(content) : 'SMS';
|
|
69
|
+
if (messageType == 'LMS')
|
|
70
|
+
acc.messageType = messageType;
|
|
71
|
+
acc.messages.push({
|
|
72
|
+
to: to,
|
|
73
|
+
...(content != undefined && { content: content }),
|
|
74
|
+
...(subject != undefined && acc.messageType === 'LMS' && { subject: subject }),
|
|
75
|
+
});
|
|
76
|
+
return acc;
|
|
77
|
+
}, init);
|
|
78
|
+
return output;
|
|
78
79
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const SMS_MAX = 90;
|
|
2
|
+
export const LMS_MAX = 2000;
|
|
3
|
+
export const MMS_FILE_MAX = 300; // KiByte
|
|
4
|
+
export const trimText = (input) => input.trim();
|
|
5
|
+
export const prettyPhoneNum = (input) => input.replace(/\-/gi, "");
|
|
6
|
+
/** @returns content-length(euc-kr) */
|
|
7
|
+
export const getContentLength = (input) => {
|
|
8
|
+
return input.split('').reduce((acc, text) => {
|
|
9
|
+
let byte = Buffer.from(text).length;
|
|
10
|
+
let modulo = byte % 3;
|
|
11
|
+
modulo ? acc += 1 : acc += 2;
|
|
12
|
+
return acc;
|
|
13
|
+
}, 0);
|
|
14
|
+
};
|
|
@@ -5,5 +5,6 @@ export * from './GetAlimtalkTemplateCommand';
|
|
|
5
5
|
export * from './ListAlimtalkTemplatesCommand';
|
|
6
6
|
export * from './ListAlimtalkChannelsCommand';
|
|
7
7
|
export * from './SendSMSCommand';
|
|
8
|
+
export * from './SendMMSCommand';
|
|
8
9
|
export * from './GetSMSStatusCommand';
|
|
9
10
|
export * from './GetSMSResultCommand';
|
|
@@ -3,7 +3,7 @@ export const middlewareIngestkoreaMetadata = async (request, config) => {
|
|
|
3
3
|
request.headers = {
|
|
4
4
|
...request.headers,
|
|
5
5
|
['x-ingestkorea-date']: longDate,
|
|
6
|
-
['x-ingestkorea-user-agent']: '@ingestkorea/client-sens/1.
|
|
6
|
+
['x-ingestkorea-user-agent']: '@ingestkorea/client-sens/1.5.x'
|
|
7
7
|
};
|
|
8
8
|
return request;
|
|
9
9
|
};
|
package/dist-es/models/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpRequest } from '@ingestkorea/util-http-handler';
|
|
2
|
-
import { parseBody, parseErrorBody } from '
|
|
2
|
+
import { parseBody, parseErrorBody } from './constants';
|
|
3
3
|
export const serializeIngestkorea_restJson_GetSMSResultCommand = async (input, config) => {
|
|
4
4
|
const hostname = "sens.apigw.ntruss.com";
|
|
5
5
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages" + '/' + input.messageId;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpRequest } from '@ingestkorea/util-http-handler';
|
|
2
|
-
import { parseBody, parseErrorBody } from '
|
|
2
|
+
import { parseBody, parseErrorBody } from './constants';
|
|
3
3
|
export const serializeIngestkorea_restJson_GetSMSStatusCommand = async (input, config) => {
|
|
4
4
|
const hostname = "sens.apigw.ntruss.com";
|
|
5
5
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { HttpRequest } from '@ingestkorea/util-http-handler';
|
|
2
|
+
import { parseBody, parseErrorBody } from './constants';
|
|
3
|
+
export const serializeIngestkorea_restJson_SendMMSCommand = async (input, config) => {
|
|
4
|
+
const hostname = "sens.apigw.ntruss.com";
|
|
5
|
+
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
6
|
+
const headers = {
|
|
7
|
+
"content-type": "application/json; charset=utf-8",
|
|
8
|
+
"host": hostname
|
|
9
|
+
};
|
|
10
|
+
const body = JSON.stringify({
|
|
11
|
+
from: input.from,
|
|
12
|
+
content: input.content,
|
|
13
|
+
messages: input.messages,
|
|
14
|
+
type: input.type != undefined ? input.type : 'MMS',
|
|
15
|
+
files: input.files,
|
|
16
|
+
...(input.contentType != undefined && { contentType: input.contentType }),
|
|
17
|
+
...(input.countryCode != undefined && { countryCode: input.countryCode }),
|
|
18
|
+
...(input.subject != undefined && { subject: input.subject }),
|
|
19
|
+
});
|
|
20
|
+
return new HttpRequest({
|
|
21
|
+
protocol: 'https:',
|
|
22
|
+
method: 'POST',
|
|
23
|
+
hostname: hostname,
|
|
24
|
+
path: path,
|
|
25
|
+
headers: headers,
|
|
26
|
+
body: body
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
export const deserializeIngestkorea_restJson_SendMMSCommand = async (output) => {
|
|
30
|
+
if (output.statusCode > 300)
|
|
31
|
+
await parseErrorBody(output);
|
|
32
|
+
const data = await parseBody(output); // SendSMSOutput
|
|
33
|
+
let contents = {};
|
|
34
|
+
contents = await deserializeIngestkorea_restJson_SendMMSOutput(data);
|
|
35
|
+
const response = {
|
|
36
|
+
...contents
|
|
37
|
+
};
|
|
38
|
+
return response;
|
|
39
|
+
};
|
|
40
|
+
export const deserializeIngestkorea_restJson_SendMMSOutput = async (output) => {
|
|
41
|
+
return {
|
|
42
|
+
requestId: output.requestId ? output.requestId : undefined,
|
|
43
|
+
requestTime: output.requestTime ? output.requestTime : undefined,
|
|
44
|
+
statusCode: output.statusCode ? output.statusCode : undefined,
|
|
45
|
+
statusName: output.statusName ? output.statusName : undefined,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpRequest } from '@ingestkorea/util-http-handler';
|
|
2
|
-
import { parseBody, parseErrorBody } from '
|
|
2
|
+
import { parseBody, parseErrorBody } from './constants';
|
|
3
3
|
export const serializeIngestkorea_restJson_SendSMSCommand = async (input, config) => {
|
|
4
4
|
const hostname = "sens.apigw.ntruss.com";
|
|
5
5
|
const path = "/sms/v2/services/" + config.serviceId.sms + "/messages";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
|
|
2
|
+
import { SensCommand, SendMMSInput, SendMMSOutput } from '../models';
|
|
3
|
+
import { SensClientResolvedConfig } from '../SensClient';
|
|
4
|
+
export interface SendMMSCommandInput extends SendMMSInput {
|
|
5
|
+
}
|
|
6
|
+
export interface SendMMSCommandOutput extends SendMMSOutput {
|
|
7
|
+
}
|
|
8
|
+
export declare class SendMMSCommand extends SensCommand<SendMMSCommandInput, SendMMSCommandOutput, SensClientResolvedConfig> {
|
|
9
|
+
input: SendMMSCommandInput;
|
|
10
|
+
constructor(input: SendMMSCommandInput);
|
|
11
|
+
serialize(input: SendMMSCommandInput, config: SensClientResolvedConfig): Promise<HttpRequest>;
|
|
12
|
+
deserialize(response: HttpResponse): Promise<SendMMSCommandOutput>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const SMS_MAX = 90;
|
|
2
|
+
export declare const LMS_MAX = 2000;
|
|
3
|
+
export declare const MMS_FILE_MAX = 300;
|
|
4
|
+
export declare const trimText: (input: string) => string;
|
|
5
|
+
export declare const prettyPhoneNum: (input: string) => string;
|
|
6
|
+
/** @returns content-length(euc-kr) */
|
|
7
|
+
export declare const getContentLength: (input: string) => number;
|
|
@@ -5,5 +5,6 @@ export * from './GetAlimtalkTemplateCommand';
|
|
|
5
5
|
export * from './ListAlimtalkTemplatesCommand';
|
|
6
6
|
export * from './ListAlimtalkChannelsCommand';
|
|
7
7
|
export * from './SendSMSCommand';
|
|
8
|
+
export * from './SendMMSCommand';
|
|
8
9
|
export * from './GetSMSStatusCommand';
|
|
9
10
|
export * from './GetSMSResultCommand';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SendSMSInput, SendSMSOutput } from './SendSMS';
|
|
2
|
+
export type SendFile = {
|
|
3
|
+
name: string;
|
|
4
|
+
body?: string;
|
|
5
|
+
};
|
|
6
|
+
export interface SendMMSInput extends SendSMSInput {
|
|
7
|
+
files: SendFile[];
|
|
8
|
+
}
|
|
9
|
+
export interface SendMMSOutput extends SendSMSOutput {
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse } from '@ingestkorea/util-http-handler';
|
|
2
|
+
import { SendMMSOutput } from '../models/SendMMS';
|
|
3
|
+
import { SensClientResolvedConfig } from '../SensClient';
|
|
4
|
+
import { SendMMSCommandInput, SendMMSCommandOutput } from '../commands/SendMMSCommand';
|
|
5
|
+
export declare const serializeIngestkorea_restJson_SendMMSCommand: (input: SendMMSCommandInput, config: SensClientResolvedConfig) => Promise<HttpRequest>;
|
|
6
|
+
export declare const deserializeIngestkorea_restJson_SendMMSCommand: (output: HttpResponse) => Promise<SendMMSCommandOutput>;
|
|
7
|
+
export declare const deserializeIngestkorea_restJson_SendMMSOutput: (output: any) => Promise<SendMMSOutput>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingestkorea/client-sens",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "INGESTKOREA SDK Naver Cloud Platform SENS Client for Node.js.",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -27,8 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@ingestkorea/util-error-handler": "^1.0.3",
|
|
30
|
-
"@ingestkorea/util-http-handler": "^1.0.0"
|
|
31
|
-
"@ingestkorea/util-simple-logger": "^1.0.3"
|
|
30
|
+
"@ingestkorea/util-http-handler": "^1.0.0"
|
|
32
31
|
},
|
|
33
32
|
"keywords": [
|
|
34
33
|
"sens",
|