UNPKG

rcs-data

Version:

RCS消息数据结构

107 lines 4.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Builder = exports.RcsMsgBuilder = void 0; const common_1 = require("../common"); const constants_1 = require("./constants"); const Text_1 = require("./Text"); const ImdnDemand_1 = require("./ImdnDemand"); const File_1 = require("./File"); const Card_1 = require("./Card"); const ImdnReply_1 = require("./ImdnReply"); const SuggestionResponse_1 = require("./SuggestionResponse"); class RcsMsgBuilder { sender(value) { if (value === undefined) return this._sender; this._sender = typeof value === 'string' ? common_1.NameAddrHeader.parse(value) : value; return this; } conversationId(value) { if (value === undefined) return this._conversationId; this._conversationId = value; return this; } contributionId(value) { if (value === undefined) return this._contributionId; this._contributionId = value; return this; } messageId(value) { if (value === undefined) return this._messageId; this._messageId = value; return this; } text(recipient, input) { let rcstext = new Text_1.Text(input); rcstext.from = this._sender; rcstext.to = recipient; rcstext.conversationId = this._conversationId; rcstext.contributionId = this._contributionId; let imdn = new ImdnDemand_1.ImdnDemand(rcstext); imdn.messageId = this._messageId; return imdn; } file(recipient, fileInfo, thumbnail) { let rcsfile = new File_1.File(fileInfo, thumbnail); rcsfile.from = this._sender; rcsfile.to = recipient; rcsfile.conversationId = this._conversationId; rcsfile.contributionId = this._contributionId; let cpim = new ImdnDemand_1.ImdnDemand(rcsfile, true, this._messageId); return cpim; } card(recipient, frame) { let rcsmsg = (0, Card_1.build)({ generalPurposeCard: frame }); rcsmsg.from = this._sender; rcsmsg.to = recipient; rcsmsg.conversationId = this._conversationId; rcsmsg.contributionId = this._contributionId; let cpim = new ImdnDemand_1.ImdnDemand(rcsmsg, true, this._messageId); return cpim; } cardCarousel(recipient, frame) { let rcsmsg = (0, Card_1.build)({ generalPurposeCardCarousel: frame }); rcsmsg.from = this._sender; rcsmsg.to = recipient; rcsmsg.conversationId = this._conversationId; rcsmsg.contributionId = this._contributionId; let cpim = new ImdnDemand_1.ImdnDemand(rcsmsg, true, this._messageId); return cpim; } imdnDelivery(replied, recipient, status = constants_1.Delivery_Status.delivered) { let { messageId, dateTime } = replied; let reply = new ImdnReply_1.ImdnReplyDelivery({ messageId, dateTime }, status, this._sender, recipient, new common_1.DateTime(), this._messageId); return reply; } imdnDisplay(replied, recipient, status = constants_1.Display_Status.displayed) { let { messageId, dateTime } = replied; let reply = new ImdnReply_1.ImdnReplyDisplay({ messageId, dateTime }, status, this._sender, recipient, new common_1.DateTime(), this._messageId); return reply; } suggestionResponse(recipient, response) { let { type, displayText, postback } = response; let sugrsp = SuggestionResponse_1.Builder.of(type) .displayText(displayText) .postbackData(postback) .build(); sugrsp.from = this._sender; sugrsp.to = recipient; sugrsp.conversationId = this._conversationId; sugrsp.contributionId = this._contributionId; let cpim = new ImdnDemand_1.ImdnDemand(sugrsp, true, this._messageId); return cpim; } } exports.RcsMsgBuilder = RcsMsgBuilder; function Builder(sender) { const builder = new RcsMsgBuilder(); if (sender) builder.sender(sender); return builder; } exports.Builder = Builder; //# sourceMappingURL=Builder.js.map