[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[fbot8] Hacking the messenger

Locate the main file of the demo server

As usual in node, the main file to start the server is named app.js and is located under node subfolder of the project.
When you produce the demo Bot, the project given by Facebook includes the node subfolder and app.js.
If you have setup the Demo in previous steps, you know where it is.

Now we can an U8 image to start development of our system incrementally

  1. Download the Node platform files in a new folder
  2. Copy the n8.snapshot.js and node_modules subfolder to node subfolder of your bot project
  3. Edit the n8.snapshot.js file (with a text editor)
    1. Copy the text contained in app.js at start of n8.snapshot.js file
    2. So, we will start the app.js as usual, starting the Demo app handler
      then, load the U8 snapshot and S8 System Server to connect our remote tools.

Start our dual server for development

  1. Start the snapshot as a node server
    Running the command: node n8.snapshot.js
  2. You must see in the console the lines
    Node app is running on port 5000
    SystemServer running at http://192.xxx.xxx.xxx:8088

    where 192.xxx.xxx.xxx is the address in your local network to access the S8 System Server
  3. Now we can use U8 tools in web browser to work as usual
    1. Open a workspace/SystemBrowser/etc tool and connect to system server address to work on remote (bot) system.

Connect your locally-hosted server to Facebook

Follow the Facebook guides to connect the server through tunnel to your app in Facebook Messenger.
  1. Open a new console window
  2. Run the tunneling command
    It should be a command like: lt -p 5000
    Use lt -help to read more on tunneling arguments
  3. Take note (copy) the URL to access your server
    It should be something like: https://iqnlfngiys.localtunnel.me
  4. Enter the page to set the webhook of your application
    It should be an URL like:
  5. Press the [Edit Subscription] button and paste in the "Callback URL" the URL given by tunnel followed by /webhook, Enter "TOKEN" to the token box; and send submission
At this point you must see a new line in the console of th ebot saying "Validating webhook"

Test your bot from Messenger and from U8 environment

To test your Bot send a message using Facebook Messenger.
It should work as usual; we have our S8 environment inside the BOT server (published by app), but we have made NOTHING that can have direct nor side effects.

To test the S8 Smalltalk environment running in the BOT we will access the system using the U8 tools.
Try accessing the system with workspace or system browser, while the BOT is attanding the webhook.
  1. Connect a workspace to the SystemServer address
  2. Evaluate the following expression to show the properties of the app handler
You should see something like this
 _events: ???;
 _eventsCount: 1;
 _maxListeners: ;
 _router: (function router(req, res, next) {...});
 acl: (function (path){...});
 addListener: (function addListener(type, listener) {...});
 all: (function all(path) {...});
 bind: (function (path){...});
 cache: [object Object];
 checkout: (function (path){...});
 connect: (function (path){...});
 copy: (function (path){...});
 defaultConfiguration: (function defaultConfiguration() {...});
 del: (function (arg0) {...});
 delete: (function (path){...});
 disable: (function disable(setting) {...});
 disabled: (function disabled(setting) {...});
 domain: ;
 emit: (function emit(type) {...});
 enable: (function enable(setting) {...});
 enabled: (function enabled(setting) {...});
 engine: (function engine(ext, fn) {...});
 engines: [object Object];
 eventNames: (function eventNames() {...});
 get: (function (path){...});
 getMaxListeners: (function getMaxListeners() {...});
 handle: (function handle(req, res, callback) {...});
 head: (function (path){...});
 init: (function init() {...});
 lazyrouter: (function lazyrouter() {...});
 link: (function (path){...});
 listen: (function listen() {...});
 listenerCount: (function listenerCount(type) {...});
 listeners: (function listeners(type) {...});
 locals: ???;
 lock: (function (path){...});
 m-search: (function (path){...});
 merge: (function (path){...});
 mkactivity: (function (path){...});
 mkcalendar: (function (path){...});
 mkcol: (function (path){...});
 mountpath: '/';
 move: (function (path){...});
 notify: (function (path){...});
 on: (function addListener(type, listener) {...});
 once: (function once(type, listener) {...});
 options: (function (path){...});
 param: (function param(name, fn) {...});
 patch: (function (path){...});
 path: (function path() {...});
 post: (function (path){...});
 prependListener: (function prependListener(type, listener) {...});
 prependOnceListener: (function prependOnceListener(type, listener) {...});
 propfind: (function (path){...});
 proppatch: (function (path){...});
 purge: (function (path){...});
 put: (function (path){...});
 rebind: (function (path){...});
 removeAllListeners: (function removeAllListeners(type) {...});
 removeListener: (function removeListener(type, listener) {...});
 render: (function render(name, options, callback) {...});
 report: (function (path){...});
 request: [object Object];
 response: [object Object];
 route: (function route(path) {...});
 search: (function (path){...});
 set: (function set(setting, val) {...});
 setMaxListeners: (function setMaxListeners(n) {...});
 settings: [object Object];
 subscribe: (function (path){...});
 trace: (function (path){...});
 unbind: (function (path){...});
 unlink: (function (path){...});
 unlock: (function (path){...});
 unsubscribe: (function (path){...});
 use: (function use(fn) {...});

Next: [fbot8] Embedding the App server