Skip to content

Commit

Permalink
How to contribute button added (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manveer695 authored and mariobehling committed Sep 5, 2017
1 parent f18e6f7 commit d13b688
Showing 1 changed file with 150 additions and 1 deletion.
151 changes: 150 additions & 1 deletion index.js
Expand Up @@ -140,6 +140,15 @@ app.post('/', function(req, response) {
"TextSize": "large",
"TextVAlign": "middle",
"TextHAlign": "middle"
},{
Columns: 6,
Rows: 1,
Text: "<font color=#323232><b>How to contribute?</b></font>",
"ActionType": "reply",
"ActionBody": "Contribution",
"TextSize": "large",
"TextVAlign": "middle",
"TextHAlign": "middle"
}];

var options2 = {
Expand All @@ -153,7 +162,7 @@ app.post('/', function(req, response) {
rich_media: {
Type: "rich_media",
ButtonsGroupColumns: 6,
ButtonsGroupRows: 2,
ButtonsGroupRows: 3,
BgColor: "#FFFFFF",
Buttons: buttons
}
Expand Down Expand Up @@ -258,6 +267,146 @@ app.post('/', function(req, response) {
});
});
}
else if(message === "Contribution"){
// setting options to request susi bot.
var options1 = {
method: 'GET',
url: 'http://api.susi.ai/susi/chat.json',
qs: {
timezoneOffset: '-330',
q: message
}
};

// A request to the Susi bot
request(options1, function(error1, response1, body1) {
if (error1) throw new Error(error1);
// answer fetched from susi
ans = (JSON.parse(body1)).answers[0].actions[0].expression;

var options = {
method: 'POST',
url: 'https://chatapi.viber.com/pa/send_message',
headers: headerBody,
body: {
receiver: req.body.sender.id,
min_api_version: 1,
tracking_data: 'tracking data',
type: 'text',
text: ans
},
json: true
};

// request to the chat api of viber.
request(options, function(error, res, body) {
if (error) throw new Error(error);

var buttons = [{
Columns: 6,
Rows: 1,
Text: "<font color=#323232><b>Visit repository</b></font>",
"ActionType": "open-url",
"ActionBody": "https://www.github.com/fossasia/susi_server",
"TextSize": "large",
"TextVAlign": "middle",
"TextHAlign": "middle"
}];

var options2 = {
method: 'POST',
url: 'https://chatapi.viber.com/pa/send_message',
headers: headerBody,
body: {
receiver: req.body.sender.id,
min_api_version: 2,
type: 'rich_media',
rich_media: {
Type: "rich_media",
ButtonsGroupColumns: 6,
ButtonsGroupRows: 1,
BgColor: "#FFFFFF",
Buttons: buttons
}
},
json: true
};

request(options2, function(error2, res2, body2) {
if (error) throw new Error(error);

var options4 = {
method: 'GET',
url: 'http://api.susi.ai/susi/chat.json',
qs: {
timezoneOffset: '-330',
q: 'Gitter channel'
}
};

// A request to the Susi bot
request(options4, function(error1, response1, body1) {
if (error1) throw new Error(error1);
// answer fetched from susi
ans = (JSON.parse(body1)).answers[0].actions[0].expression;

var options5 = {
method: 'POST',
url: 'https://chatapi.viber.com/pa/send_message',
headers: headerBody,
body: {
receiver: req.body.sender.id,
min_api_version: 1,
tracking_data: 'tracking data',
type: 'text',
text: ans
},
json: true
};

// request to the chat api of viber.
request(options5, function(error, res, body) {
if (error) throw new Error(error);

var buttons = [{
Columns: 6,
Rows: 1,
Text: "<font color=#323232><b>Chat on Gitter</b></font>",
"ActionType": "open-url",
"ActionBody": "https://www.gitter.im/fossasia/susi_server",
"TextSize": "large",
"TextVAlign": "middle",
"TextHAlign": "middle"
}];

var options6 = {
method: 'POST',
url: 'https://chatapi.viber.com/pa/send_message',
headers: headerBody,
body: {
receiver: req.body.sender.id,
min_api_version: 2,
type: 'rich_media',
rich_media: {
Type: "rich_media",
ButtonsGroupColumns: 6,
ButtonsGroupRows: 1,
BgColor: "#FFFFFF",
Buttons: buttons
}
},
json: true
};

request(options6, function(error2, res2, body2) {
if (error) throw new Error(error);
});
});
});
});
});
});
}
else{
// setting options to request susi bot.
var options1 = {
Expand Down

0 comments on commit d13b688

Please sign in to comment.