Repository: Yoctol/bottender (ts)

Issue:
ConsoleBot fallbackMethods support sendText second argument?
In Messenger, we put quick replies and other options like tag in second argument. But those will be ignored when using ConsoleBot with `fallbackMethods`.

Pull request description:
prettify ConsoleBot fallbackMethods output
close #297 

![default](https://user-images.githubusercontent.com/1003146/42445343-7302617a-83a5-11e8-835e-c40d11638a28.png)
![default](https://user-images.githubusercontent.com/1003146/42445366-7f0635be-83a5-11e8-9cd8-f8f85dc36e79.png)


Patch:
diff --git a/src/context/ConsoleContext.js b/src/context/ConsoleContext.js
index a236a69a..3787d4dc 100644
--- a/src/context/ConsoleContext.js
+++ b/src/context/ConsoleContext.js
@@ -27,6 +27,8 @@ export default class ConsoleContext extends Context implements PlatformContext {
   _event: ConsoleEvent;
   _session: ?Session;
 
+  _fallbackMethods: boolean = false;
+
   constructor({
     client,
     event,
@@ -36,6 +38,7 @@ export default class ConsoleContext extends Context implements PlatformContext {
     fallbackMethods,
   }: Options) {
     super({ client, event, session, initialState, requestContext });
+    this._fallbackMethods = fallbackMethods;
     if (fallbackMethods) {
       // $FlowExpectedError
       return new Proxy(this, {
@@ -79,13 +82,21 @@ export default class ConsoleContext extends Context implements PlatformContext {
    * Send text to the owner of then session.
    *
    */
-  async sendText(text: string): Promise<void> {
+  async sendText(text: string, ...args: Array<any>): Promise<void> {
     this._isHandled = true;
-    this._client.sendText(text);
+    if (args && this._fallbackMethods) {
+      this._client.sendText(
+        `${text}\nwith other args:\n${JSON.stringify(args, null, 2)}`
+      );
+    } else {
+      this._client.sendText(text);
+    }
   }
 
   async _methodMissing(method: string, args: Array<any>): Promise<void> {
     this._isHandled = true;
-    this._client.sendText(`${method}: ${JSON.stringify(args)}`);
+    this._client.sendText(
+      `${method} with args:\n${JSON.stringify(args, null, 2)}`
+    );
   }
 }


Test patch:
diff --git a/src/context/__tests__/ConsoleContext.spec.js b/src/context/__tests__/ConsoleContext.spec.js
index e644aaed..532d78d9 100644
--- a/src/context/__tests__/ConsoleContext.spec.js
+++ b/src/context/__tests__/ConsoleContext.spec.js
@@ -87,6 +87,16 @@ describe('#sendText', () => {
 
     expect(context.isHandled).toBe(true);
   });
+
+  it('should support fallbackMethods with other args', async () => {
+    const { context, client } = setup({ fallbackMethods: true });
+
+    await context.sendText('hello', { other: 1 });
+
+    expect(client.sendText).toBeCalledWith(
+      `hello\nwith other args:\n${JSON.stringify([{ other: 1 }], null, 2)}`
+    );
+  });
 });
 
 describe('method missing', () => {
@@ -95,7 +105,13 @@ describe('method missing', () => {
 
     await context.sendABC('hello', { json: true });
 
-    expect(client.sendText).toBeCalledWith('sendABC: ["hello",{"json":true}]');
+    expect(client.sendText).toBeCalledWith(
+      `sendABC with args:\n${JSON.stringify(
+        ['hello', { json: true }],
+        null,
+        2
+      )}`
+    );
   });
 
   it('should mark context as handled', async () => {