Repository: Yoctol/bottender
Pull request #67 (2017-12-04 04:02:20)

Add huge likesticker to MessengerEvent.js


Patch:
diff --git a/src/context/MessengerEvent.js b/src/context/MessengerEvent.js
index 1dcef53c..de92e9e6 100644
--- a/src/context/MessengerEvent.js
+++ b/src/context/MessengerEvent.js
@@ -41,12 +41,17 @@ type MediaAttachment = {
 
 type Attachment = MediaAttachment | FallbackAttachment;
 
+type Tag = {|
+  source: string,
+|};
+
 export type Message = {
   is_echo?: boolean,
   text?: string,
   sticker_id?: number,
   quick_reply?: QuickReply,
   attachments?: Array<Attachment>,
+  tags?: Array<Tag>,
 };
 
 export type Delivery = {
@@ -344,13 +349,16 @@ export default class MessengerEvent implements Event {
 
   /**
    * Determine if the event is a message event which includes 'like' sticker.
-   *
+   * id 369239263222822 is a small like sticker
+   * id 369239263222814 is a large like sticker
+   * id 369239263222810 is a huge like sticker
    */
   get isLikeSticker(): boolean {
     return (
       this.isSticker &&
       ((this.message: any).sticker_id === 369239263222822 ||
-        (this.message: any).sticker_id === 369239343222814)
+        (this.message: any).sticker_id === 369239343222814 ||
+        (this.message: any).sticker_id === 369239383222810)
     );
   }
 
@@ -612,4 +620,19 @@ export default class MessengerEvent implements Event {
   get takeThreadControl(): ?TakeThreadControl {
     return this._rawEvent.take_thread_control || null;
   }
+
+  /**
+   * Determine if the event is from customer chat plugin.
+   *
+   */
+  get isFromCustomerChatPlugin(): boolean {
+    return (
+      this.isMessage &&
+      !!(this.message: any).tags &&
+      (this.message: any).tags.length !== 0 &&
+      (this.message: any).tags.some(
+        tag => tag.source === 'customer_chat_plugin'
+      )
+    );
+  }
 }


Test patch:
diff --git a/src/context/__tests__/MessengerEvent.spec.js b/src/context/__tests__/MessengerEvent.spec.js
index 54e59a9e..ac84e1e6 100644
--- a/src/context/__tests__/MessengerEvent.spec.js
+++ b/src/context/__tests__/MessengerEvent.spec.js
@@ -197,6 +197,31 @@ const largeLikeStickerMessage = {
   },
 };
 
+const hugeLikeStickerMessage = {
+  sender: {
+    id: '1423587017700273',
+  },
+  recipient: {
+    id: '404217156637689',
+  },
+  timestamp: 1491797086506,
+  message: {
+    mid: 'mid.$cAAE1UUyiiwthh05ZKlbVgkOobi32',
+    seq: 348853,
+    sticker_id: 369239383222810,
+    attachments: [
+      {
+        type: 'image',
+        payload: {
+          url:
+            'https://scontent.xx.fbcdn.net/v/t39.1997-6/p100x100/851587_369239346556147_162929011_n.png?_nc_ad=z-m&oh=2008c832edbd2376b09a1008358b8fd9&oe=598FC1B0',
+          sticker_id: 369239383222810,
+        },
+      },
+    ],
+  },
+};
+
 const quickReplyMessage = {
   sender: {
     id: '1423587017700273',
@@ -416,6 +441,22 @@ const takeThreadControl = {
   },
 };
 
+const textMessageFromCustomerChatPlugin = {
+  sender: { id: '1423587017700273' },
+  recipient: { id: '404217156637689' },
+  timestamp: 1491796363181,
+  message: {
+    mid: 'mid.$cAAE1UUyiiwthh0NPrVbVf4HFNDGl',
+    seq: 348847,
+    text: 'Sharp tools make good work.',
+    tags: [
+      {
+        source: 'customer_chat_plugin',
+      },
+    ],
+  },
+};
+
 it('#rawEvent', () => {
   expect(new MessengerEvent(textMessage).rawEvent).toEqual(textMessage);
   expect(new MessengerEvent(imageMessage).rawEvent).toEqual(imageMessage);
@@ -435,6 +476,9 @@ it('#isMessage', () => {
   expect(new MessengerEvent(imageMessage).isMessage).toEqual(true);
   expect(new MessengerEvent(likeStickerMessage).isMessage).toEqual(true);
   expect(new MessengerEvent(quickReplyMessage).isMessage).toEqual(true);
+  expect(
+    new MessengerEvent(textMessageFromCustomerChatPlugin).isMessage
+  ).toEqual(true);
   expect(new MessengerEvent(echoMessage).isMessage).toEqual(true);
   expect(new MessengerEvent(postback).isMessage).toEqual(false);
   expect(new MessengerEvent(payment).isMessage).toEqual(false);
@@ -676,6 +720,7 @@ it('#isSticker', () => {
   expect(new MessengerEvent(imageMessage).isSticker).toEqual(false);
   expect(new MessengerEvent(likeStickerMessage).isSticker).toEqual(true);
   expect(new MessengerEvent(largeLikeStickerMessage).isSticker).toEqual(true);
+  expect(new MessengerEvent(hugeLikeStickerMessage).isSticker).toEqual(true);
 });
 
 it('#sticker', () => {
@@ -687,6 +732,9 @@ it('#sticker', () => {
   expect(new MessengerEvent(largeLikeStickerMessage).sticker).toEqual(
     369239343222814
   );
+  expect(new MessengerEvent(hugeLikeStickerMessage).sticker).toEqual(
+    369239383222810
+  );
 });
 
 it('#isLikeSticker', () => {
@@ -696,6 +744,9 @@ it('#isLikeSticker', () => {
   expect(new MessengerEvent(largeLikeStickerMessage).isLikeSticker).toEqual(
     true
   );
+  expect(new MessengerEvent(hugeLikeStickerMessage).isLikeSticker).toEqual(
+    true
+  );
 });
 
 it('#isQuickReply', () => {
@@ -998,3 +1049,14 @@ it('#takeThreadControl', () => {
     previous_owner_app_id: '123456789',
   });
 });
+
+it('#isFromCustomerChatPlugin', () => {
+  expect(new MessengerEvent(textMessage).isFromCustomerChatPlugin).toEqual(
+    false
+  );
+  expect(new MessengerEvent(postback).isFromCustomerChatPlugin).toEqual(false);
+  expect(
+    new MessengerEvent(textMessageFromCustomerChatPlugin)
+      .isFromCustomerChatPlugin
+  ).toEqual(true);
+});