Skip to content

Commit

Permalink
微修正
Browse files Browse the repository at this point in the history
  • Loading branch information
MotokiKasaharaBansuke committed Feb 27, 2020
1 parent d33fa71 commit 2a9518e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 72 deletions.
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"env": {
"LD_LIBRARY_PATH": {
"value": "/app/.linuxbrew/lib"
},
}
},
"buildpacks": [
{
"url": "https://github.com/stomita/heroku-buildpack-phantomjs"
}
},
{
"url": "https://github.com/sunny4381/heroku-buildpack-linuxbrew.git"
}
Expand Down
3 changes: 1 addition & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ module.exports = {
ALGOLIA_API_KEY: "",
ALGOLIA_INDEX_NAME: "",
A3RT_API_KEY: ""
};

};
1 change: 0 additions & 1 deletion logics/_a3rt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = (text, cb) => {
query: text
}
}, (err, res, body) => {
console.log(body)
if (err) {
console.log(err);
return cb(err);
Expand Down
2 changes: 1 addition & 1 deletion logics/_send.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (path, body, cb) => {
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Authorization': `Bearer ${TOKEN}`
Authorization: `Bearer ${TOKEN}`
}
}, (err, res, body) => {

Expand Down
48 changes: 0 additions & 48 deletions logics/_send_hmac.js

This file was deleted.

35 changes: 17 additions & 18 deletions routes/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@ const router = express.Router();
const algoliasearch = require('algoliasearch');
const _send = require('../logics/_send');
const _a3rt = require('../logics/_a3rt');
const _send_hmac = require('../logics/_send_hmac');
const _search = require('../logics/_search');


// webhook
router.post('/echo', (req, res, next) => {

const {CLIENT_ID, API_KEY} = require('../config');
const {event_type, user_id, assignee, app_name, message_id, thread_id, content, from_user} = req.body;
const {event_type, user_id, assignee, app_name, content} = req.body;

if (event_type === 'message') {

// 自分がアサインされていたら、メッセージを送る
if (assignee.id === CLIENT_ID) {
_send('message', {
'client_id': CLIENT_ID,
'api_key': API_KEY,
client_id: CLIENT_ID,
api_key: API_KEY,
app_name,
user_id,
content: {
text: `僕はエコーサーバーです: ${content.text}`
},
'from_user': false
from_user: false
}, (err) => {

if (err) {
Expand All @@ -35,12 +34,12 @@ router.post('/echo', (req, res, next) => {
} else {
// 自分がアサインされていなければ、有無を言わさずアサインする
_send('assign', {
'client_id': CLIENT_ID,
'api_key': API_KEY,
client_id: CLIENT_ID,
api_key: API_KEY,
user_id,
assignee:{
"id":CLIENT_ID,
"is_bot":true
id:CLIENT_ID,
is_bot:true
}
}, (err) => {

Expand All @@ -54,14 +53,14 @@ router.post('/echo', (req, res, next) => {

if (assignee.id === CLIENT_ID) {
_send('message', {
'client_id': CLIENT_ID,
'api_key': API_KEY,
client_id: CLIENT_ID,
api_key: API_KEY,
app_name: 'webchat',
user_id,
content: {
text: 'こんにちわ。わたしKARTE Botが担当します。 '
},
'from_user': false
from_user: false
});
}
}
Expand All @@ -75,7 +74,7 @@ router.post('/echo', (req, res, next) => {
router.post('/a3rt', (req, res, next) => {

const {CLIENT_ID, API_KEY} = require('../config');
const {event_type, user_id, assignee, app_name, message_id, thread_id, content, from_user} = req.body;
const {event_type, user_id, assignee, app_name, content} = req.body;

if (event_type === 'message') {

Expand All @@ -89,14 +88,14 @@ router.post('/a3rt', (req, res, next) => {
}

return _send('message', {
'client_id': CLIENT_ID,
'api_key': API_KEY,
client_id: CLIENT_ID,
api_key: API_KEY,
app_name,
user_id,
content: {
text
},
'from_user': false
from_user: false
}, (err) => {

if (err) {
Expand All @@ -115,7 +114,7 @@ router.post('/a3rt', (req, res, next) => {
// webhook
router.post('/operator', (req, res, next) => {
const {CLIENT_ID, API_KEY} = require('../config');
const {event_type, user_id, assignee, app_name, message_id, thread_id, content, from_user} = req.body;
const {event_type, user_id, assignee, content} = req.body;
if (event_type === 'assign') {
if (assignee.id === CLIENT_ID) {
_send_delayed_msgs(user_id, [
Expand Down Expand Up @@ -213,7 +212,7 @@ const _send_delayed_msgs = (user_id, texts, client_id, api_key) => {
content: {
text: txt
},
'from_user': false
from_user: false
}, resolve)

, i * 1000);
Expand Down

0 comments on commit 2a9518e

Please sign in to comment.