Skip to content

Commit

Permalink
added viber examples (#101)
Browse files Browse the repository at this point in the history
* added viber examples

* Update example
  • Loading branch information
chentsulin authored and kpman committed Dec 14, 2017
1 parent 53ae22e commit d9f9823
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/console-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ It shows how to build a most basic console bot.
* [line-hello-world](../line-hello-world)
* [slack-hello-world](../slack-hello-world)
* [telegram-hello-world](../telegram-hello-world)
* [viber-hello-world](../viber-hello-world)
1 change: 1 addition & 0 deletions examples/line-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ This example shows how to combine
* [messenger-builder](../messenger-builder)
* [slack-builder](../slack-builder)
* [telegram-builder](../telegram-builder)
* [viber-builder](../viber-builder)
1 change: 1 addition & 0 deletions examples/line-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ For more information, check our [LINE guides](https://bottender.js.org/docs/Plat
* [console-hello-world](../console-hello-world)
* [slack-hello-world](../slack-hello-world)
* [telegram-hello-world](../telegram-hello-world)
* [viber-hello-world](../viber-hello-world)
1 change: 1 addition & 0 deletions examples/messenger-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ For more information, check our [Messenger guides](https://bottender.js.org/docs
* [line-builder](../line-builder)
* [slack-builder](../slack-builder)
* [telegram-builder](../telegram-builder)
* [viber-builder](../viber-builder)
1 change: 1 addition & 0 deletions examples/messenger-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ For more information, check our [Messenger guides](https://bottender.js.org/docs
* [line-hello-world](../line-hello-world)
* [slack-hello-world](../slack-hello-world)
* [telegram-hello-world](../telegram-hello-world)
* [viber-hello-world](../viber-hello-world)
1 change: 1 addition & 0 deletions examples/slack-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ For more information, check our [Slack guides](https://bottender.js.org/docs/Pla
* [messenger-builder](../messenger-builder)
* [line-builder](../line-builder)
* [telegram-builder](../telegram-builder)
* [viber-builder](../viber-builder)
1 change: 1 addition & 0 deletions examples/slack-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ For more information, check our [Slack guides](https://bottender.js.org/docs/Pla
* [messenger-hello-world](../messenger-hello-world)
* [slack-hello-world](../slack-hello-world)
* [telegram-hello-world](../telegram-hello-world)
* [viber-hello-world](../viber-hello-world)
1 change: 1 addition & 0 deletions examples/telegram-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ For more information, check our [Telegram guides](https://bottender.js.org/docs/
* [messenger-builder](../messenger-builder)
* [line-builder](../line-builder)
* [slack-builder](../slack-builder)
* [viber-builder](../viber-builder)
1 change: 1 addition & 0 deletions examples/telegram-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ For more information, check our [Telegram guides](https://bottender.js.org/docs/
* [messenger-hello-world](../messenger-hello-world)
* [line-hello-world](../line-hello-world)
* [slack-hello-world](../slack-hello-world)
* [viber-hello-world](../viber-hello-world)
27 changes: 27 additions & 0 deletions examples/viber-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Viber builder

## Install and Run

Download this example or clone [bottender](https://github.com/Yoctol/bottender).

```
curl https://codeload.github.com/Yoctol/bottender/tar.gz/master | tar -xz --strip=2 bottender-master/examples/viber-builder
cd viber-builder
npm install
npm run dev
```

## Idea of this example

This example shows how to combine
[handler](https://bottender.js.org/docs/APIReference-Handler) with
[Viber](https://www.viber.com/) bot. You have to get `accessToken` before running this bot.\
For more information, check our [Viber guides](https://bottender.js.org/docs/Platforms-Viber).

## Related examples

* [viber-hello-world](../viber-hello-world)
* [messenger-builder](../messenger-builder)
* [line-builder](../line-builder)
* [slack-builder](../slack-builder)
* [telegram-builder](../telegram-builder)
33 changes: 33 additions & 0 deletions examples/viber-builder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { ViberBot, ViberHandler } = require('bottender');
const { createServer } = require('bottender/express');

const bot = new ViberBot({
accessToken: '__FILL_YOUR_TOKEN_HERE__',
});

const handler = new ViberHandler()
.onDelivered(() => {
console.log('delivered');
})
.onSeen(() => {
console.log('seen');
})
.onFailed(() => {
console.log('failed');
})
.onText(/yo/i, async context => {
await context.sendText('Hi there!');
})
.onEvent(async context => {
await context.sendText("I don't know what you say.");
})
.onError(async context => {
await context.sendText('Something wrong happened.');
});

bot.onEvent(handler);

const server = createServer(bot);
server.listen(5000, () => {
console.log('server is running on 5000 port...');
});
12 changes: 12 additions & 0 deletions examples/viber-builder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dependencies": {
"bottender": "latest"
},
"devDependencies": {
"nodemon": "^1.11.0"
},
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js"
}
}
27 changes: 27 additions & 0 deletions examples/viber-hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Viber hello world

## Install and Run

Download this example or clone [bottender](https://github.com/Yoctol/bottender).

```
curl https://codeload.github.com/Yoctol/bottender/tar.gz/master | tar -xz --strip=2 bottender-master/examples/viber-hello-world
cd viber-hello-world
npm install
npm run dev
```

## Idea of this example

This example is a simple bot running on [Viber](https://www.viber.com/).
You have to get `accessToken` before running this bot.\
For more information, check our [Viber guides](https://bottender.js.org/docs/Platforms-Viber).

## Related examples

* [viber-builder](../viber-builder)
* [console-hello-world](../console-hello-world)
* [messenger-hello-world](../messenger-hello-world)
* [line-hello-world](../line-hello-world)
* [slack-hello-world](../slack-hello-world)
* [telegram-hello-world](../telegram-hello-world)
18 changes: 18 additions & 0 deletions examples/viber-hello-world/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { ViberBot } = require('bottender');
const { createServer } = require('bottender/express');

const bot = new ViberBot({
accessToken: '__FILL_YOUR_TOKEN_HERE__',
});

bot.onEvent(async context => {
if (context.event.isMessage) {
await context.sendText('Hello World');
}
});

const server = createServer(bot);

server.listen(5000, () => {
console.log('server is running on 5000 port...');
});
12 changes: 12 additions & 0 deletions examples/viber-hello-world/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dependencies": {
"bottender": "latest"
},
"devDependencies": {
"nodemon": "^1.11.0"
},
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js"
}
}
3 changes: 3 additions & 0 deletions examples/with-config/bottender.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ module.exports = {
accessToken: '__PUT_YOUR_ACCESS_TOKEN_HERE__',
verificationToken: '__FILL_YOUR_VERIFICATION_TOKEN_HERE__',
},
viber: {
accessToken: '__PUT_YOUR_ACCESS_TOKEN_HERE__',
},
ngrok: true,
};

0 comments on commit d9f9823

Please sign in to comment.