-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,97 @@ | ||
# fb-local-chat-bot | ||
|
||
Testing your Messenger Bot apps is a pain in the ass - you need to setup ngrok to tunnel to your server (what happens when multiple people work on it?) and writing unit tests are not intuitive. | ||
|
||
fb-local-chat-bot is | ||
- standard library that handles the boilerplate logic to connect with FB APIs | ||
- local web client to debug the app (see screenshot) | ||
- intuitive APIs for unit testing | ||
|
||
# Demo | ||
 | ||
|
||
## Install | ||
``` | ||
npm install fb-local-chat-bot | ||
``` | ||
|
||
## Examlpe | ||
# Code Snippet | ||
|
||
## Initialize | ||
``` | ||
// app.js | ||
Bot.init( | ||
config.FBChatToken || '', | ||
'SETUP_PLAY_GO_THIS_IS_RIGHT', | ||
config.useFBChatLocalTest || false, | ||
); | ||
Bot.on('text', async (event: object) => { | ||
// do something | ||
}); | ||
Bot.on('attachments', async (event: object) => { | ||
// do something | ||
}); | ||
Bot.on('postback', async (event: object) => { | ||
// do something | ||
}); | ||
app.use('/webhook', Bot.router()); | ||
// go to http://localhost:5000/webhook/localChat/ for local chat debugging | ||
``` | ||
|
||
## Send APIs | ||
``` | ||
// generic send API | ||
Bot.send(userID, messageData); | ||
// send text | ||
Bot.sendText(userID, "Yo what's up how you doin"); | ||
// send image | ||
Bot.sendText(userID, imageURL); | ||
// send buttons | ||
Bot.sendButtons( | ||
userID, | ||
'Some text', | ||
[ | ||
Bot.createPostbackButton( | ||
'button 1', | ||
'BUTTON_TYPE_1', | ||
), | ||
Bot.createPostbackButton( | ||
'button 2', | ||
'BUTTON_TYPE_2', | ||
), | ||
] | ||
); | ||
``` | ||
|
||
## Testing APIs | ||
``` | ||
describe('Basic server test', function() { | ||
this.timeout(1000); | ||
var server; | ||
var userID = 'testUser'; | ||
beforeEach(mochaAsync(async () => { | ||
server = await makeServer(true /* silent */); | ||
})); | ||
afterEach(function (done) { | ||
Bot.clearLocalChatMessages(); | ||
Bot.removeAllListeners(); | ||
server.close(done); | ||
}); | ||
it('Test help', mochaAsync(async () => { | ||
await ResponseHandler.handleText(userID, "help"); | ||
let messages = Bot.getLocalChatMessagesForUser(userID); | ||
expect(messages.length).to.equal(2); | ||
})); | ||
}); | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.