UNPKG

@ingestkorea/client-sens

Version:

INGESTKOREA SDK Naver Cloud Platform SENS Client for Node.js.

53 lines (52 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveInputMessages = exports.SendSMSCommand = void 0; const index_js_1 = require("../models/index.js"); const SendSMS_js_1 = require("../protocols/SendSMS.js"); const constants_1 = require("./constants"); class SendSMSCommand extends index_js_1.SensCommand { constructor(input) { super(input); const content = input.content ? (0, constants_1.trimText)(input.content) : "내용없음"; const subject = input.subject ? (0, constants_1.trimText)(input.subject) : "제목없음"; const messages = (0, exports.resolveInputMessages)(input.messages, { defaultContent: content, defaultSubject: subject }); const isLMS = !!messages.filter((msg) => !!msg.subject).length; this.input = Object.assign({ from: (0, constants_1.prettyPhoneNum)(input.from), content, messages, type: isLMS ? "LMS" : "SMS", contentType: input.contentType ? input.contentType : "COMM", countryCode: input.countryCode ? input.countryCode : "82" }, (isLMS && { subject })); this.serializer = SendSMS_js_1.se_SendSMSCommand; this.deserializer = SendSMS_js_1.de_SendSMSCommand; } } exports.SendSMSCommand = SendSMSCommand; const resolveInputMessages = (messages, config) => { const output = messages .filter((d) => !!d) .map((message) => { const content = message.content ? (0, constants_1.trimText)(message.content) : config.defaultContent; const subject = message.subject ? (0, constants_1.trimText)(message.subject) : config.defaultSubject; const msgType = getMessageType({ content }); return Object.assign({ to: (0, constants_1.prettyPhoneNum)(message.to), content }, (msgType === "LMS" && { subject })); }); return output; }; exports.resolveInputMessages = resolveInputMessages; const getMessageType = (input) => { const SMS_MAX_CONTENT_LENGTH = 90; const LMS_MAX_CONTENT_LENGTH = 2000; const contentLength = (0, constants_1.getContentLength)(input.content); if (!contentLength) { throw new index_js_1.SensError({ code: -1, type: "SDK.GENERAL_ERROR", message: "메세지 내용이 없습니다.", }); } if (contentLength > LMS_MAX_CONTENT_LENGTH) { throw new index_js_1.SensError({ code: -1, type: "SDK.GENERAL_ERROR", message: `메세지 최대 길이는 ${LMS_MAX_CONTENT_LENGTH}글자입니다`, }); } return contentLength > SMS_MAX_CONTENT_LENGTH ? "LMS" : "SMS"; };