Skip to content

Commit

Permalink
Extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Fay Montage committed Feb 3, 2017
0 parents commit 4650271
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
state
node_modules
docker-compose.yml
.gradle
.idea
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
client: java $JAVA_OPTS -jar client/bin/token-headless-client.jar config/config-heroku.yml
bot: node bot/src/bot.js config/config-heroku.yml
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Token SOFA App

## Developing a SOFA app for token

### Bots

### WebViews

## Deploying

### Deploy on Heroku

### Deploy with Docker
15 changes: 15 additions & 0 deletions bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# latest official node image
FROM node:latest

RUN npm install -g nodemon

# use cached layer for node modules
#ADD package.json /tmp/package.json
#RUN cd /tmp && npm install
#RUN mkdir -p /usr/src/bot && cp -a /tmp/node_modules /usr/src/bot/

# add project files
ADD . /usr/src/bot
WORKDIR /usr/src/bot

CMD npm install && nodemon -L src/bot.js config.yml
15 changes: 15 additions & 0 deletions bot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "token-bot-foundation",
"version": "1.0.0",
"description": "",
"main": "src/bot.js",
"dependencies": {
"token-headless-bot": "file:///usr/src/token-headless-bot"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Token",
"license": "ISC"
}
82 changes: 82 additions & 0 deletions bot/src/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const SOFA = require('token-headless-bot').SOFA;
const Bot = require('token-headless-bot').Bot;

let bot = new Bot();

bot.hear('ping', (session, message) => {
session.reply(SOFA.Message({body: "pong"}));
})

bot.hear('SOFA::Init:', (session, message) => {
session.reply("I will pay you at "+message.content.paymentAddress+" and speak to you in "+message.content.language);
})

bot.hear('SOFA::Payment:', (session, message) => {
session.reply("Thanks for the loot.");
})

bot.hear('SOFA::PaymentRequest:', (session, message) => {
session.reply("I ain't paying you a dime.");
})

bot.hear('initMe', (session, message) => {
session.reply(SOFA.InitRequest({
values: ['paymentAddress', 'language']
}));
})

bot.hear('begMe', (session, message) => {
session.reply(SOFA.PaymentRequest({
body: "Thanks for the great time! Can you send your share of the tab?",
value: "0xce0eb154f900000",
destinationAddress: "0x056db290f8ba3250ca64a45d16284d04bc6f5fbf"
}));
})

bot.hear('SOFA::Command:', (session, message) => {
session.reply("I was commanded: ", message.content.value);
})

bot.hear('buttons', (session, message) => {
session.reply(SOFA.Message({
body: "Now let’s try sending some money. Choose a charity to make a donation of $0.01.",
controls: [
{type: "button", label: "Red Cross", value: "red-cross"},
{type: "button", label: "Ethereum foundation", value: "ethereum-foundation"},
{type: "button", label: "GiveWell.org", value: "givewell.org"},
{type: "button", label: "Not now, thanks", value: null}
]
}));
})

bot.hear('groups', (session, message) => {
session.reply(SOFA.Message({
body: "What would you like me to do for you right now?",
controls: [
{
type: "group",
label: "Trip",
controls: [
{type: "button", label: "Directions", action: "Webview:/Directions"},
{type: "button", label: "Timetable", value: "timetable"},
{type: "button", label: "Exit Info", value: "exit"},
{type: "button", label: "Service Conditions", action: "Webview:/ServiceConditions"}
]
},{
type: "group",
label: "Services",
controls: [
{type: "button", label: "Buy Ticket", action: "buy-ticket"},
{type: "button", label: "Support", value: "support"}
]
},
{type: "button", label: "Nothing", value: -1}
],
showKeyboard: false
}));
})


bot.hear('SOFA::Message:', (session, message) => {
session.reply("I hear you "+session.address);
});
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
task stage {
//dummy to trigger Heroku gradle buildpack
}
4 changes: 4 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:8
COPY . /usr/src/client
WORKDIR /usr/src/client
CMD ["java", "-jar", "bin/token-headless-client.jar", "config.yml"]
Binary file added client/bin/token-headless-client.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions config/config-heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server: https://token-chat-service.herokuapp.com
store: store
redis:
envKey: REDIS_URL
timeout: 2000
5 changes: 5 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server: https://token-chat-service.herokuapp.com
store: /state
redis:
envKey: REDIS_URL
timeout: 2000
24 changes: 24 additions & 0 deletions docker-compose.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '2'
services:
client:
build: client
links:
- redis
environment: &environment
- TOKEN_ADDRESS=
- TOKEN_CLIENT_SEED=
- REDIS_URL=
volumes:
- ./state/client:/state
- ./config/config.yml:/usr/src/client/config.yml
bot:
build: bot
links:
- redis
environment: *environment
volumes:
- ./state/bot:/state
- ./config/config.yml:/usr/src/bot/config.yml
- ./bot/src:/usr/src/bot/src
redis:
build: redis
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"postinstall": "cd bot && npm install"
}
}
1 change: 1 addition & 0 deletions redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redis.conf
3 changes: 3 additions & 0 deletions redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM redis
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
5 changes: 5 additions & 0 deletions redis/redis.conf.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
port 6379
timeout 0
loglevel notice
databases 16
requirepass myNiceLongPassword
1 change: 1 addition & 0 deletions system.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java.runtime.version=1.8

0 comments on commit 4650271

Please sign in to comment.