UNPKG

@ingestkorea/client-sens

Version:

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

49 lines (48 loc) 1.8 kB
import { SensCommand } from "../models"; import { serializeIngestkorea_restJson_SendAlimtalkCommand, deserializeIngestkorea_restJson_SendAlimtalkCommand, } from "../protocols/SendAlimtalk"; import { IngestkoreaError } from "@ingestkorea/util-error-handler"; export class SendAlimtalkCommand extends SensCommand { constructor(input) { super(input); this.input = { ...input, plusFriendId: input.plusFriendId, templateCode: input.templateCode, messages: resolveAlimtalkMessage(input.messages), }; } async serialize(input, config) { if (!config.serviceId.kakao) throw new IngestkoreaError({ code: 400, type: "Bad Request", message: "Invalid Params", description: "Please Check Kakao ServiceId", }); let request = await serializeIngestkorea_restJson_SendAlimtalkCommand(input, config); return request; } async deserialize(response) { let output = await deserializeIngestkorea_restJson_SendAlimtalkCommand(response); return output; } } const resolveAlimtalkMessage = (messages) => { const ALIMTALK_MAX = 1000; const lastError = new IngestkoreaError({ code: 400, type: "Bad Request", message: "Invalid Params", description: `Maximum message length is ${ALIMTALK_MAX}`, }); const result = messages.map((message) => { if (message.content.length > ALIMTALK_MAX) throw lastError; return { to: message.to.replace(/\-/gi, ""), content: message.content, ...(message.buttons && message.buttons.length && { buttons: message.buttons }), }; }); return result; };