dop-sdk
Version:
Mini App SDK for JavaScript by VTB
97 lines • 4.21 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatService = void 0;
var event_types_1 = require("../event-types");
var sdkbridge_1 = require("../sdkbridge");
/** @internal */
var ChatService = /** @class */ (function () {
function ChatService() {
}
/**
* @param message The message to send to contact.
* @returns Promise resolves with the contact id received a message.
* Can also resolve with null response in the case that the message was not sent to a contact, such as if the user cancelled sending the message.
* Promise rejects in the case that there was an error.
* It returns error info if user had denied the custom permission for sending message.
*/
ChatService.prototype.sendMessageToContact = function (message) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.ChatServiceEvent.SEND_MESSAGE_TO_CONTACT, {
messageToContact: __assign(__assign({}, message), { bannerMessage: trimBannerText(message.bannerMessage) }),
})
.then(function (contactId) {
if (contactId !== 'null' && contactId !== null) {
return contactId;
}
else {
return null;
}
})
.catch(function (error) { return error; });
};
/**
* @param id The id of the contact receiving a message.
* @param message The message to send to contact.
* @returns Promise resolves with the contact id received a message.
* @see {sendMessageToContact}
*/
ChatService.prototype.sendMessageToContactId = function (id, message) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.ChatServiceEvent.SEND_MESSAGE_TO_CONTACT_ID, {
contactId: id,
messageToContact: __assign(__assign({}, message), { bannerMessage: trimBannerText(message.bannerMessage) }),
})
.then(function (contactId) {
if (contactId !== 'null' && contactId !== null) {
return contactId;
}
else {
return null;
}
})
.catch(function (error) { return error; });
};
/**
* @param message The message to send to contact.
* @returns Promise resolves with an array of contact id which were sent the message.
* Can also resolve with null array in the case that the message was not sent to any contacts, such as if the user cancelled sending the message.
* Promise rejects in the case that there was an error.
* It returns error info if user had denied the custom permission for sending message.
*/
ChatService.prototype.sendMessageToMultipleContacts = function (message) {
return (0, sdkbridge_1.getBridge)()
.sendToNative(event_types_1.ChatServiceEvent.SEND_MESSAGE_TO_MULTIPLE_CONTACTS, {
messageToContact: __assign(__assign({}, message), { bannerMessage: trimBannerText(message.bannerMessage) }),
})
.then(function (contactIds) {
if (contactIds !== 'null' && contactIds !== null) {
return JSON.parse(contactIds);
}
else {
return null;
}
})
.catch(function (error) { return error; });
};
return ChatService;
}());
exports.ChatService = ChatService;
function trimBannerText(message, maxLength) {
if (message === void 0) { message = null; }
if (maxLength === void 0) { maxLength = 128; }
return (message === null || message === void 0 ? void 0 : message.length) > maxLength
? (message === null || message === void 0 ? void 0 : message.substring(0, maxLength - 1)) + '…'
: message;
}
//# sourceMappingURL=chat-service.js.map