crisp-api 6.0.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/crisp.js CHANGED
@@ -24,6 +24,7 @@ Crisp.DEFAULT_SOCKET_RECONNECT_DELAY = 5000;
24
24
  Crisp.DEFAULT_SOCKET_RECONNECT_DELAY_MAX = 10000;
25
25
  Crisp.DEFAULT_SOCKET_RECONNECT_FACTOR = 0.75;
26
26
  Crisp.DEFAULT_SOCKET_SCHEDULE = 500;
27
+ Crisp.DEFAULT_EVENT_REBIND_INTERVAL_MIN = 2500;
27
28
  Crisp.DEFAULT_USERAGENT_PREFIX = "node-crisp-api/";
28
29
 
29
30
 
@@ -68,6 +69,7 @@ Crisp.DEFAULT_RTM_EVENTS = [
68
69
  "message:updated",
69
70
  "message:send",
70
71
  "message:received",
72
+ "message:removed",
71
73
  "message:compose:send",
72
74
  "message:compose:receive",
73
75
  "message:acknowledge:read:send",
@@ -175,6 +177,9 @@ function Crisp() {
175
177
  /** @private */
176
178
  this._socketScheduler = null;
177
179
 
180
+ /** @private */
181
+ this._lastEventRebind = null;
182
+
178
183
  /** @private */
179
184
  this._socketBindHooks = [];
180
185
 
@@ -407,7 +412,7 @@ Crisp.prototype = {
407
412
  return this._prepareSocket(
408
413
  function(socket, emitter) {
409
414
  // Listen for event (once socket is bound)
410
- socket.on(event, function(data) {
415
+ socket.on(event, function(data) {
411
416
  emitter.emit(event, data);
412
417
  });
413
418
  }
@@ -417,6 +422,38 @@ Crisp.prototype = {
417
422
  return Promise.resolve();
418
423
  },
419
424
 
425
+ /**
426
+ * Rebind socket events
427
+ * @memberof Crisp
428
+ * @method rebind
429
+ */
430
+ rebind : function() {
431
+ if (!this._socket) {
432
+ throw new Error(
433
+ "[Crisp] rebind: cannot rebind a socket that is not yet bound"
434
+ );
435
+ }
436
+
437
+ // Make sure that the library user is not rebinding too frequently (which \
438
+ // is illegal)
439
+ var nowTime = Date.now();
440
+
441
+ if (this._lastEventRebind !== null &&
442
+ ((nowTime - this._lastEventRebind) <
443
+ Crisp.DEFAULT_EVENT_REBIND_INTERVAL_MIN)) {
444
+ throw new Error(
445
+ "[Crisp] rebind: cannot rebind, last rebind was requested too recently"
446
+ );
447
+ }
448
+
449
+ // Rebind to socket events (eg. newly bound websites)
450
+ this._lastEventRebind = nowTime;
451
+
452
+ this._socket.emit("socket:bind", {});
453
+
454
+ return Promise.resolve();
455
+ },
456
+
420
457
  /**
421
458
  * Prepare a URI based from path segments
422
459
  * @memberof Crisp
@@ -238,6 +238,22 @@ function WebsiteConversation(service, crisp) {
238
238
  );
239
239
  };
240
240
 
241
+ /**
242
+ * Remove A Message In Conversation
243
+ * @memberof WebsiteConversation
244
+ * @method removeMessageInConversation
245
+ * @return Promise
246
+ */
247
+ service.removeMessageInConversation = function(
248
+ websiteID, sessionID, fingerprint
249
+ ) {
250
+ return crisp.delete(
251
+ crisp._prepareRestUrl([
252
+ "website", websiteID, "conversation", sessionID, "message", fingerprint
253
+ ])
254
+ );
255
+ };
256
+
241
257
  /**
242
258
  * Compose A Message In Conversation
243
259
  * @memberof WebsiteConversation
@@ -518,6 +534,42 @@ function WebsiteConversation(service, crisp) {
518
534
  );
519
535
  };
520
536
 
537
+ /**
538
+ * Get Verify Status For Conversation
539
+ * @memberof WebsiteConversation
540
+ * @method getVerifyStatusForConversation
541
+ * @return Promise
542
+ */
543
+ service.getVerifyStatusForConversation = function(websiteID, sessionID) {
544
+ return crisp.get(
545
+ crisp._prepareRestUrl([
546
+ "website", websiteID, "conversation", sessionID, "verify"
547
+ ])
548
+ );
549
+ };
550
+
551
+ /**
552
+ * Update Verify Status For Conversation
553
+ * @memberof WebsiteConversation
554
+ * @method updateVerifyStatusForConversation
555
+ * @return Promise
556
+ */
557
+ service.updateVerifyStatusForConversation = function(
558
+ websiteID, sessionID, verified
559
+ ) {
560
+ return crisp.patch(
561
+ crisp._prepareRestUrl([
562
+ "website", websiteID, "conversation", sessionID, "verify"
563
+ ]),
564
+
565
+ null,
566
+
567
+ {
568
+ verified : (verified || false)
569
+ }
570
+ );
571
+ };
572
+
521
573
  /**
522
574
  * Request Email Transcript For Conversation
523
575
  * @memberof WebsiteConversation
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "crisp-api",
3
3
  "description": "Crisp API wrapper for Node - official, maintained by Crisp",
4
- "version": "6.0.0",
4
+ "version": "6.3.0",
5
5
  "homepage": "https://github.com/crisp-im/node-crisp-api",
6
6
  "license": "MIT",
7
7
  "author": {
package/types/crisp.d.ts CHANGED
@@ -25,6 +25,8 @@ declare class Crisp {
25
25
  /** @private */
26
26
  private _socketScheduler;
27
27
  /** @private */
28
+ private _lastEventRebind;
29
+ /** @private */
28
30
  private _socketBindHooks;
29
31
  /** @private */
30
32
  private _boundEvents;
@@ -40,6 +42,7 @@ declare class Crisp {
40
42
  put: (resource: string, query: object, body: object) => any;
41
43
  delete: (resource: string, query: object, body: object) => any;
42
44
  on: (event: string, callback: Function) => void;
45
+ rebind: () => void;
43
46
  _prepareRestUrl: (paths: any[]) => string;
44
47
  _prepareServices: () => void;
45
48
  _prepareResources: (serviceInstance: object, resources: any[]) => void;
@@ -48,7 +51,7 @@ declare class Crisp {
48
51
  _emitAuthenticate: () => void;
49
52
  }
50
53
  declare namespace Crisp {
51
- export { DEFAULT_REQUEST_TIMEOUT, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SOCKET_RECONNECT_DELAY, DEFAULT_SOCKET_RECONNECT_DELAY_MAX, DEFAULT_SOCKET_RECONNECT_FACTOR, DEFAULT_SOCKET_SCHEDULE, DEFAULT_USERAGENT_PREFIX, DEFAULT_REST_HOST, DEFAULT_REST_BASE_PATH, DEFAULT_RTM_EVENTS, Crisp };
54
+ export { DEFAULT_REQUEST_TIMEOUT, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SOCKET_RECONNECT_DELAY, DEFAULT_SOCKET_RECONNECT_DELAY_MAX, DEFAULT_SOCKET_RECONNECT_FACTOR, DEFAULT_SOCKET_SCHEDULE, DEFAULT_EVENT_REBIND_INTERVAL_MIN, DEFAULT_USERAGENT_PREFIX, DEFAULT_REST_HOST, DEFAULT_REST_BASE_PATH, DEFAULT_RTM_EVENTS, Crisp };
52
55
  }
53
56
  declare var DEFAULT_REQUEST_TIMEOUT: number;
54
57
  declare var DEFAULT_SOCKET_TIMEOUT: number;
@@ -56,6 +59,7 @@ declare var DEFAULT_SOCKET_RECONNECT_DELAY: number;
56
59
  declare var DEFAULT_SOCKET_RECONNECT_DELAY_MAX: number;
57
60
  declare var DEFAULT_SOCKET_RECONNECT_FACTOR: number;
58
61
  declare var DEFAULT_SOCKET_SCHEDULE: number;
62
+ declare var DEFAULT_EVENT_REBIND_INTERVAL_MIN: number;
59
63
  declare var DEFAULT_USERAGENT_PREFIX: string;
60
64
  declare var DEFAULT_REST_HOST: string;
61
65
  declare var DEFAULT_REST_BASE_PATH: string;