crisp-api 6.3.2 → 6.4.1

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/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## v6.4.1
5
+
6
+ ### Bug Fixes
7
+
8
+ * Return more informative error reasons for non `2xx / 3xx` response codes on `HEAD` requests.
9
+
10
+ ## v6.4.0
11
+
12
+ ### New Features
13
+
14
+ * Added the new `CrispClient.website.requestUserFeedbackForConversation` method.
15
+
4
16
  ## v6.3.2
5
17
 
6
18
  ### Bug Fixes
package/EXAMPLES.md CHANGED
@@ -402,6 +402,15 @@ CrispClient.website.requestChatboxBindingPurgeForConversation(websiteID, session
402
402
 
403
403
  =========================
404
404
 
405
+ https://docs.crisp.chat/references/rest-api/v1/#request-user-feedback-for-conversation
406
+
407
+ var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
408
+ var sessionID = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881";
409
+
410
+ CrispClient.website.requestUserFeedbackForConversation(websiteID, sessionID);
411
+
412
+ =========================
413
+
405
414
  https://docs.crisp.chat/references/rest-api/v1/#list-browsing-sessions-for-conversation
406
415
 
407
416
  var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
package/README.md CHANGED
@@ -716,6 +716,19 @@ All methods that you will most likely need when building a Crisp integration are
716
716
  ```
717
717
  </details>
718
718
 
719
+ * **Request User Feedback For Conversation** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#request-user-feedback-for-conversation)
720
+ * `CrispClient.website.requestUserFeedbackForConversation(websiteID, sessionID)`
721
+ * <details>
722
+ <summary>See Example</summary>
723
+
724
+ ```javascript
725
+ var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
726
+ var sessionID = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881";
727
+
728
+ CrispClient.website.requestUserFeedbackForConversation(websiteID, sessionID);
729
+ ```
730
+ </details>
731
+
719
732
  * **List Browsing Sessions For Conversation** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#list-browsing-sessions-for-conversation)
720
733
  * `CrispClient.website.listBrowsingSessionsForConversation(websiteID, sessionID)`
721
734
  * <details>
package/lib/crisp.js CHANGED
@@ -29,8 +29,8 @@ Crisp.DEFAULT_USERAGENT_PREFIX = "node-crisp-api/";
29
29
 
30
30
 
31
31
  // REST API defaults
32
- Crisp.DEFAULT_REST_HOST = "https://api.crisp.chat";
33
- Crisp.DEFAULT_REST_BASE_PATH = "/v1/";
32
+ Crisp.DEFAULT_REST_HOST = "https://api.crisp.chat";
33
+ Crisp.DEFAULT_REST_BASE_PATH = "/v1/";
34
34
 
35
35
 
36
36
  // RTM API defaults
@@ -666,21 +666,23 @@ Crisp.prototype = {
666
666
  * @param {function} reject
667
667
  */
668
668
  _request : function(resource, method, query, body, resolve, reject) {
669
+ var self = this;
670
+
669
671
  var requestParameters = {
670
672
  responseType : "json",
671
673
  timeout : Crisp.DEFAULT_REQUEST_TIMEOUT,
672
674
 
673
675
  headers : {
674
- "User-Agent" : this._useragent,
675
- "X-Crisp-Tier" : this._tier
676
+ "User-Agent" : self._useragent,
677
+ "X-Crisp-Tier" : self._tier
676
678
  },
677
679
 
678
680
  throwHttpErrors : false
679
681
  };
680
682
 
681
683
  // Add authorization?
682
- if (this.auth.token) {
683
- requestParameters.headers.Authorization = ("Basic " + this.auth.token);
684
+ if (self.auth.token) {
685
+ requestParameters.headers.Authorization = ("Basic " + self.auth.token);
684
686
  }
685
687
 
686
688
  // Add body?
@@ -720,7 +722,9 @@ Crisp.prototype = {
720
722
 
721
723
  // Response error?
722
724
  if (response.statusCode >= 400) {
723
- var reason_message = ((response.body || {}).reason || "http_error");
725
+ var reason_message = self._readErrorResponseReason(
726
+ method, response.statusCode, response
727
+ );
724
728
  var data_message = ((response.body || {}).data || {}).message;
725
729
 
726
730
  return reject({
@@ -780,6 +784,35 @@ Crisp.prototype = {
780
784
  tier : tier,
781
785
  events : this._boundEvents
782
786
  });
787
+ },
788
+
789
+ /**
790
+ * Reads reason for error response
791
+ * @memberof Crisp
792
+ * @private
793
+ * @method _readErrorResponseReason
794
+ * @param {string} method
795
+ * @param {number} statusCode
796
+ * @param {object} response
797
+ */
798
+ _readErrorResponseReason : function(method, statusCode, response) {
799
+ // HEAD method? As HEAD requests do not expect any response body, then we \
800
+ // cannot map a reason from the response.
801
+ if (method === "head") {
802
+ // 5xx errors?
803
+ if (statusCode >= 500) {
804
+ return "server_error";
805
+ }
806
+
807
+ // 4xx errors?
808
+ if (statusCode >= 400) {
809
+ return "route_error";
810
+ }
811
+ }
812
+
813
+ // Other methods must hold a response body, therefore we can fallback on \
814
+ // an HTTP error if we fail to acquire any reason at all.
815
+ return ((response.body || {}).reason || "http_error");
783
816
  }
784
817
  };
785
818
 
@@ -613,6 +613,22 @@ function WebsiteConversation(service, crisp) {
613
613
  );
614
614
  };
615
615
 
616
+ /**
617
+ * Request User Feedback For Conversation
618
+ * @memberof WebsiteConversation
619
+ * @method requestUserFeedbackForConversation
620
+ * @return Promise
621
+ */
622
+ service.requestUserFeedbackForConversation = function(
623
+ websiteID, sessionID
624
+ ) {
625
+ return crisp.post(
626
+ crisp._prepareRestUrl([
627
+ "website", websiteID, "conversation", sessionID, "feedback"
628
+ ])
629
+ );
630
+ };
631
+
616
632
  /**
617
633
  * List Browsing Sessions For Conversation
618
634
  * @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.3.2",
4
+ "version": "6.4.1",
5
5
  "homepage": "https://github.com/crisp-im/node-crisp-api",
6
6
  "license": "MIT",
7
7
  "author": {