UNPKG

crisp-api

Version:

Crisp API wrapper for Node - official, maintained by Crisp

610 lines (609 loc) 19.3 kB
"use strict"; /* * This file is part of node-crisp-api * * Copyright (c) 2025 Crisp IM SAS * All rights belong to Crisp IM SAS */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /************************************************************************** * IMPORTS ***************************************************************************/ // PROJECT: RESOURCES const BaseResource_1 = __importDefault(require("./BaseResource")); /************************************************************************** * CLASSES ***************************************************************************/ /** * Crisp WebsiteConversation Resource * @class */ class WebsiteConversation extends BaseResource_1.default { /** * List Conversations */ listConversations(websiteID, pageNumber = 1, options) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", String(pageNumber) ]), options); } ; /** * List Suggested Conversation Segments */ listSuggestedConversationSegments(websiteID, pageNumber = 1) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", "suggest", "segments", String(pageNumber) ])); } ; /** * Delete Suggested Conversation Segment */ deleteSuggestedConversationSegment(websiteID, segment) { return this.crisp.delete(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", "suggest", "segment" ]), null, { segment: segment }); } ; /** * List Suggested Conversation Data Keys */ listSuggestedConversationDataKeys(websiteID, pageNumber = 1) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", "suggest", "data", String(pageNumber) ])); } ; /** * Delete Suggested Conversation Data Key */ deleteSuggestedConversationDataKey(websiteID, key) { return this.crisp.delete(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", "suggest", "data" ]), null, { key: key }); } ; /** * List Spam Conversations */ listSpamConversations(websiteID, pageNumber = 1) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", "spams", String(pageNumber) ])); } ; /** * Resolve Spam Conversation Content */ resolveSpamConversationContent(websiteID, spamID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", "spam", spamID, "content" ])); } ; /** * Submit Spam Conversation Decision */ submitSpamConversationDecision(websiteID, spamID, action) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversations", "spam", spamID, "decision" ]), null, { action: action }); } ; /** * Create A New Conversation */ createNewConversation(websiteID) { return this.crisp.post(this.crisp.prepareRestUrl(["website", websiteID, "conversation"]), null, null); } ; /** * Check If Conversation Exists */ checkConversationExists(websiteID, sessionID) { return this.crisp.head(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID ])); } ; /** * Get A Conversation */ getConversation(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID ])); } ; /** * Remove A Conversation */ removeConversation(websiteID, sessionID) { return this.crisp.delete(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID ])); } ; /** * Initiate A Conversation With Existing Session */ initiateConversationWithExistingSession(websiteID, sessionID) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "initiate" ]), null, null); } ; /** * Get Messages In Conversation */ getMessagesInConversation(websiteID, sessionID, timestampBefore) { // Generate query let query = {}; if (timestampBefore) { // @ts-ignore query.timestamp_before = String(timestampBefore); } return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "messages" ]), query); } ; /** * Send A Message In Conversation */ sendMessageInConversation(websiteID, sessionID, message) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "message" ]), null, message); } ; /** * Get A Message In Conversation */ getMessageInConversation(websiteID, sessionID, fingerprint) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "message", String(fingerprint) ])); } ; /** * Update A Message In Conversation */ updateMessageInConversation(websiteID, sessionID, fingerprint, content) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "message", String(fingerprint) ]), null, { content: content }); } ; /** * Remove A Message In Conversation */ removeMessageInConversation(websiteID, sessionID, fingerprint) { return this.crisp.delete(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "message", String(fingerprint) ])); } ; /** * Compose A Message In Conversation */ composeMessageInConversation(websiteID, sessionID, compose) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "compose" ]), null, compose); } ; /** * Mark Messages As Read In Conversation */ markMessagesReadInConversation(websiteID, sessionID, read) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "read" ]), null, read); } ; /** * Mark Conversation As Unread */ markConversationAsUnread(websiteID, sessionID, unread) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "unread" ]), null, unread); } ; /** * Mark Messages As Delivered In Conversation */ markMessagesDeliveredInConversation(websiteID, sessionID, delivered) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "delivered" ]), null, delivered); } ; /** * Update Conversation Open State */ updateConversationOpenState(websiteID, sessionID, opened) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "open" ]), null, { opened: (opened || false) }); } ; /** * Get Conversation Routing Assign */ getConversationRoutingAssign(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "routing" ])); } ; /** * Assign Conversation Routing */ assignConversationRouting(websiteID, sessionID, assign) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "routing" ]), null, assign); } ; /** * Update Conversation Inbox */ updateConversationInbox(websiteID, sessionID, inboxID) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "inbox" ]), null, { inbox_id: inboxID }); } /** * Get Conversation Metas */ getConversationMetas(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "meta" ])); } /** * Update Conversation Metas */ updateConversationMetas(websiteID, sessionID, metas) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "meta" ]), null, metas); } /** * Get An Original Message In Conversation */ getOriginalMessageInConversation(websiteID, sessionID, originalID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "original", originalID ])); } /** * List Conversation Pages */ listConversationPages(websiteID, sessionID, pageNumber = 1) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "pages", String(pageNumber) ])); } ; /** * List Conversation Events */ listConversationEvents(websiteID, sessionID, pageNumber = 1) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "events", String(pageNumber) ])); } ; /** * List Conversation Files */ listConversationFiles(websiteID, sessionID, pageNumber = 1) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "files", String(pageNumber) ])); } ; /** * Get Conversation State */ getConversationState(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "state" ])); } ; /** * Change Conversation State */ changeConversationState(websiteID, sessionID, state) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "state" ]), null, { state: state }); } ; /** * Get Conversation Participants */ getConversationParticipants(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "participants" ])); } ; /** * Save Conversation Participants */ saveConversationParticipants(websiteID, sessionID, participants) { return this.crisp.put(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "participants" ]), null, participants); } ; /** * Get Block Status For Conversation */ getBlockStatusForConversation(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "block" ])); } ; /** * Block Incoming Messages For Conversation */ blockIncomingMessagesForConversation(websiteID, sessionID, blocked) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "block" ]), null, { blocked: (blocked || false) }); } ; /** * Get Verify Status For Conversation */ getVerifyStatusForConversation(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "verify" ])); } ; /** * Update Verify Status For Conversation */ updateVerifyStatusForConversation(websiteID, sessionID, verified) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "verify" ]), null, { verified: (verified || false) }); } ; /** * Request Identity Verification For Conversation */ requestIdentityVerificationForConversation(websiteID, sessionID, verification) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "verify", "identity" ]), null, verification); } ; /** * Redeem Identity Verification Link For Conversation */ redeemIdentityVerificationLinkForConversation(websiteID, sessionID, verification) { return this.crisp.put(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "verify", "identity", "link" ]), null, verification); } ; /** * Request Email Transcript For Conversation */ requestEmailTranscriptForConversation(websiteID, sessionID, to, email) { // Generate body let body = { to: to }; if (email) { // @ts-ignore body.email = email; } return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "transcript" ]), null, body); } ; /** * Request Chatbox Binding Purge For Conversation */ requestChatboxBindingPurgeForConversation(websiteID, sessionID) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "purge" ]), null, null); } ; /** * Request User Feedback For Conversation */ requestUserFeedbackForConversation(websiteID, sessionID) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "feedback" ]), null, null); } ; /** * List Browsing Sessions For Conversation */ listBrowsingSessionsForConversation(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "browsing" ])); } ; /** * Initiate Browsing Session For Conversation */ initiateBrowsingSessionForConversation(websiteID, sessionID) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "browsing" ]), null, null); } ; /** * Send Action To An Existing Browsing Session */ sendActionToExistingBrowsingSession(websiteID, sessionID, browsingID, action) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "browsing", browsingID ]), null, { action: action }); } ; /** * Assist Existing Browsing Session */ assistExistingBrowsingSession(websiteID, sessionID, browsingID, assist) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "browsing", browsingID, "assist" ]), null, assist); } ; /** * Initiate New Call Session For Conversation */ initiateNewCallSessionForConversation(websiteID, sessionID, mode) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "call" ]), null, { mode: (mode || "audio") }); } ; /** * Get Ongoing Call Session For Conversation */ getOngoingCallSessionForConversation(websiteID, sessionID) { return this.crisp.get(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "call" ])); } ; /** * Abort Ongoing Call Session For Conversation */ abortOngoingCallSessionForConversation(websiteID, sessionID, callID) { return this.crisp.delete(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "call", callID ])); } ; /** * Transmit Signaling On Ongoing Call Session */ transmitSignalingOnOngoingCallSession(websiteID, sessionID, callID, payload) { return this.crisp.patch(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "call", callID ]), null, payload); } ; /** * Deliver Widget Button Action For Conversation */ deliverWidgetButtonActionForConversation(websiteID, sessionID, pluginID, sectionID, itemID, data, value) { // Generate body let body = { section_id: sectionID, item_id: itemID, data: data }; if (typeof value !== "undefined") { // @ts-ignore body.value = value; } return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "widget", pluginID, "button" ]), null, body); } ; /** * Deliver Widget Data Fetch Action For Conversation */ deliverWidgetDataFetchActionForConversation(websiteID, sessionID, pluginID, sectionID, itemID, data) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "widget", pluginID, "data" ]), null, { section_id: sectionID, item_id: itemID, data: data }); } ; /** * Deliver Widget Data Edit Action For Conversation */ deliverWidgetDataEditActionForConversation(websiteID, sessionID, pluginID, sectionID, itemID, value) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "widget", pluginID, "data" ]), null, { section_id: sectionID, item_id: itemID, value: value }); } ; /** * Schedule A Reminder For Conversation */ scheduleReminderForConversation(websiteID, sessionID, date, note) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "reminder" ]), null, { date: date, note: note }); } ; /** * Report Conversation */ reportConversation(websiteID, sessionID, flag) { return this.crisp.post(this.crisp.prepareRestUrl([ "website", websiteID, "conversation", sessionID, "report" ]), null, { flag: flag }); } ; } /************************************************************************** * EXPORTS ***************************************************************************/ exports.default = WebsiteConversation;