Repository: Yoctol/bottender (ts)

Issue:
implement Camera Dismiss Event
https://developers.facebook.com/docs/messenger-platform/camera-effects#dismiss

```js
{ 
  "sender": {
    "id": "<PSID>"
  },
  "recipient": {
    "id": "<PAGE_ID>"
  },
  "timestamp": 1469111400000,
  "branded_camera": { 
     "content_ids": [<CAMERA-EFFECT-ID>, <CAMERA-EFFECT-ID>, ...],
     "event": "dismiss"
  }
}
```

Pull request:
Implement branded_camera event
close #259 
docs PR: https://github.com/bottenderjs/bottenderjs.github.io/pull/59

Patch:
diff --git a/src/context/MessengerEvent.js b/src/context/MessengerEvent.js
index 48828f4d..3d5e7fa7 100644
--- a/src/context/MessengerEvent.js
+++ b/src/context/MessengerEvent.js
@@ -140,7 +140,7 @@ export type PolicyEnforcement = {
 };
 
 export type AppRoles = {
-  [key: string]: Array<String>,
+  [key: string]: Array<string>,
 };
 
 export type PassThreadControl = {
@@ -158,6 +158,11 @@ export type RequestThreadControl = {
   metadata: string,
 };
 
+export type BrandedCamera = {
+  content_ids: Array<string>,
+  event: string,
+};
+
 export type MessengerRawEvent = {
   sender?: Sender,
   recipient?: Recipient,
@@ -177,6 +182,7 @@ export type MessengerRawEvent = {
   take_thread_control?: TakeThreadControl,
   request_thread_control?: RequestThreadControl,
   referral?: Referral,
+  branded_camera?: BrandedCamera,
 };
 
 type MessengerEventOptions = {
@@ -768,4 +774,26 @@ export default class MessengerEvent implements Event {
   get pageId(): ?string {
     return this._pageId || null;
   }
+
+  /**
+   * Determine if the event is a branded_camera event.
+   *
+   */
+  get isBrandedCamera(): boolean {
+    return (
+      !!this._rawEvent.branded_camera &&
+      typeof this._rawEvent.branded_camera === 'object'
+    );
+  }
+
+  /**
+   * The branded_camera object from Messenger event.
+   *
+   */
+  get brandedCamera(): ?BrandedCamera {
+    if (!this.isBrandedCamera) {
+      return null;
+    }
+    return this._rawEvent.branded_camera;
+  }
 }


Test patch:
diff --git a/src/context/__tests__/MessengerEvent.spec.js b/src/context/__tests__/MessengerEvent.spec.js
index 82d357f4..3a563bf5 100644
--- a/src/context/__tests__/MessengerEvent.spec.js
+++ b/src/context/__tests__/MessengerEvent.spec.js
@@ -555,6 +555,20 @@ const customerChatPluginReferral = {
 
 const pageId = '137542570280111';
 
+const brandedCamera = {
+  sender: {
+    id: '1476077422222289',
+  },
+  recipient: {
+    id: '707356222221168',
+  },
+  timestamp: 1469111400000,
+  branded_camera: {
+    content_ids: ['<CAMERA-EFFECT-ID>', '<CAMERA-EFFECT-ID>'],
+    event: 'dismiss',
+  },
+};
+
 it('#rawEvent', () => {
   expect(new MessengerEvent(textMessage).rawEvent).toEqual(textMessage);
   expect(new MessengerEvent(imageMessage).rawEvent).toEqual(imageMessage);
@@ -1286,3 +1300,24 @@ it('#pageId', () => {
   );
   expect(new MessengerEvent(textMessage).pageId).toEqual(null);
 });
+
+it('#isBrandedCamera', () => {
+  expect(new MessengerEvent(textMessage).isBrandedCamera).toEqual(false);
+  expect(new MessengerEvent(postback).isBrandedCamera).toEqual(false);
+  expect(
+    new MessengerEvent(customerChatPluginReferral).isBrandedCamera
+  ).toEqual(false);
+  expect(new MessengerEvent(brandedCamera).isBrandedCamera).toEqual(true);
+});
+
+it('#brandedCamera', () => {
+  expect(new MessengerEvent(textMessage).brandedCamera).toEqual(null);
+  expect(new MessengerEvent(postback).brandedCamera).toEqual(null);
+  expect(new MessengerEvent(customerChatPluginReferral).brandedCamera).toEqual(
+    null
+  );
+  expect(new MessengerEvent(brandedCamera).brandedCamera).toEqual({
+    content_ids: ['<CAMERA-EFFECT-ID>', '<CAMERA-EFFECT-ID>'],
+    event: 'dismiss',
+  });
+});