UNPKG

intercom-client

Version:

Official Node bindings to the Intercom API

359 lines (358 loc) 23.1 kB
"use strict"; // This file was auto-generated by Fern from our API Definition. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomChannelEventsClient = void 0; const BaseClient_js_1 = require("../../../../BaseClient.js"); const headers_js_1 = require("../../../../core/headers.js"); const core = __importStar(require("../../../../core/index.js")); const environments = __importStar(require("../../../../environments.js")); const handleNonStatusCodeError_js_1 = require("../../../../errors/handleNonStatusCodeError.js"); const errors = __importStar(require("../../../../errors/index.js")); const Intercom = __importStar(require("../../../index.js")); /** * With the "Custom Channel" integration, you can bring Fin and Intercom capabilities to your own platform via API, enabling powerful custom integrations. * * Intercom treats your integration like any other Intercom channel, allowing your application and Intercom to exchange events seamlessly. This makes it possible, for example, for your users to interact with Fin directly within your own application’s UI. * * > **Note:** "Fin over API" is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. */ class CustomChannelEventsClient { constructor(options = {}) { this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options); } /** * Notifies Intercom that a new conversation was created in your custom channel/platform. This triggers conversation creation and workflow automations within Intercom for your custom channel integration. * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. * * @param {Intercom.CustomChannelBaseEvent} request * @param {CustomChannelEventsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Intercom.BadRequestError} * @throws {@link Intercom.UnauthorizedError} * @throws {@link Intercom.NotFoundError} * @throws {@link Intercom.UnprocessableEntityError} * * @example * await client.customChannelEvents.notifyNewConversation({ * event_id: "event_id", * external_conversation_id: "external_conversation_id", * contact: { * type: "user", * external_id: "external_id" * } * }) */ notifyNewConversation(request, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__notifyNewConversation(request, requestOptions)); } __notifyNewConversation(request, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, "custom_channel_events/notify_new_conversation"), method: "POST", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: request, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Intercom.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse); case 404: throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse); case 422: throw new Intercom.UnprocessableEntityError(_response.error.body, _response.rawResponse); default: throw new errors.IntercomError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/custom_channel_events/notify_new_conversation"); }); } /** * Notifies Intercom that a new message was sent in a conversation on your custom channel/platform. This allows Intercom to process the message and trigger any relevant workflow automations. * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. * * @param {Intercom.NotifyNewMessageRequest} request * @param {CustomChannelEventsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Intercom.BadRequestError} * @throws {@link Intercom.UnauthorizedError} * @throws {@link Intercom.NotFoundError} * @throws {@link Intercom.UnprocessableEntityError} * * @example * await client.customChannelEvents.notifyNewMessage({ * body: "body", * event_id: "event_id", * external_conversation_id: "external_conversation_id", * contact: { * type: "user", * external_id: "external_id" * } * }) */ notifyNewMessage(request, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__notifyNewMessage(request, requestOptions)); } __notifyNewMessage(request, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, "custom_channel_events/notify_new_message"), method: "POST", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: request, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Intercom.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse); case 404: throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse); case 422: throw new Intercom.UnprocessableEntityError(_response.error.body, _response.rawResponse); default: throw new errors.IntercomError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/custom_channel_events/notify_new_message"); }); } /** * Notifies Intercom that a user selected a quick reply option in your custom channel/platform. This allows Intercom to process the response and trigger any relevant workflow automations. * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. * * @param {Intercom.NotifyQuickReplySelectedRequest} request * @param {CustomChannelEventsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Intercom.BadRequestError} * @throws {@link Intercom.UnauthorizedError} * @throws {@link Intercom.NotFoundError} * @throws {@link Intercom.UnprocessableEntityError} * * @example * await client.customChannelEvents.notifyQuickReplySelected({ * event_id: "evt_67890", * external_conversation_id: "conv_13579", * contact: { * type: "user", * external_id: "user_003", * name: "Alice Example", * email: "alice@example.com" * }, * quick_reply_option_id: "1234" * }) */ notifyQuickReplySelected(request, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__notifyQuickReplySelected(request, requestOptions)); } __notifyQuickReplySelected(request, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, "custom_channel_events/notify_quick_reply_selected"), method: "POST", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: request, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Intercom.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse); case 404: throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse); case 422: throw new Intercom.UnprocessableEntityError(_response.error.body, _response.rawResponse); default: throw new errors.IntercomError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/custom_channel_events/notify_quick_reply_selected"); }); } /** * Notifies Intercom that a user provided a response to an attribute collector in your custom channel/platform. This allows Intercom to process the attribute and trigger any relevant workflow automations. * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. * * @param {Intercom.NotifyAttributeCollectedRequest} request * @param {CustomChannelEventsClient.RequestOptions} requestOptions - Request-specific configuration. * * @throws {@link Intercom.BadRequestError} * @throws {@link Intercom.UnauthorizedError} * @throws {@link Intercom.NotFoundError} * @throws {@link Intercom.UnprocessableEntityError} * * @example * await client.customChannelEvents.notifyAttributeCollected({ * attribute: { * id: "id", * value: "value" * }, * event_id: "event_id", * external_conversation_id: "external_conversation_id", * contact: { * type: "user", * external_id: "external_id" * } * }) */ notifyAttributeCollected(request, requestOptions) { return core.HttpResponsePromise.fromPromise(this.__notifyAttributeCollected(request, requestOptions)); } __notifyAttributeCollected(request, requestOptions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; const _authRequest = yield this._options.authProvider.getAuthRequest(); const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ "Intercom-Version": requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.version }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers); const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.IntercomEnvironment.UsProduction, "custom_channel_events/notify_attribute_collected"), method: "POST", headers: _headers, contentType: "application/json", queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams, requestType: "json", body: request, timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 20) * 1000, maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries, abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch, logging: this._options.logging, }); if (_response.ok) { return { data: _response.body, rawResponse: _response.rawResponse, }; } if (_response.error.reason === "status-code") { switch (_response.error.statusCode) { case 400: throw new Intercom.BadRequestError(_response.error.body, _response.rawResponse); case 401: throw new Intercom.UnauthorizedError(_response.error.body, _response.rawResponse); case 404: throw new Intercom.NotFoundError(_response.error.body, _response.rawResponse); case 422: throw new Intercom.UnprocessableEntityError(_response.error.body, _response.rawResponse); default: throw new errors.IntercomError({ statusCode: _response.error.statusCode, body: _response.error.body, rawResponse: _response.rawResponse, }); } } return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/custom_channel_events/notify_attribute_collected"); }); } } exports.CustomChannelEventsClient = CustomChannelEventsClient;