Skip to content

Instantly share code, notes, and snippets.

@ardianta
Last active April 26, 2017 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardianta/1eae01a2c528662bbbf5cb17aaed05a3 to your computer and use it in GitHub Desktop.
Save ardianta/1eae01a2c528662bbbf5cb17aaed05a3 to your computer and use it in GitHub Desktop.
skrip untuk integrasikan bot telegram dengan API simsimi di hook.io
module['exports'] = function iyanChanBot(hook) {
var request = require('request');
var simiUrl = 'http://sandbox.api.simsimi.com/request.p?key=0858369d-3d2d-4bcd-86b0-eaf9d523d259&lc=id&ft=1.0&text='+hook.params.message.text;
request(simiUrl, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
console.log(data);
var pesanBalasan = "";
//400-Bad Request.
// 401-Unauthorized.
// 404-Not found.
// 500-Server Error.
if(data.result == 509 || data.result == 400 || data.result == 401 || data.result == 404 || data.result == 500 ){
pesanBalasan = "iyan-chan sedang tidur, silahkan hubungi kakak @ardiantapargo!";
} else {
pesanBalasan = data.response;
pesanBalasan = data.response.replace(/Simsimi/g, "simsimi");
pesanBalasan = data.response.replace(/Simi/g, "simi");
pesanBalasan = data.response.replace(/simsimi/g, "iyan-chan");
pesanBalasan = data.response.replace(/simi/g, "iyan-chan");
}
request
.post('https://api.telegram.org/bot' + hook.env.iyan_chan_bot + '/sendMessage')
.form({
"chat_id": hook.params.message.chat.id,
"text": pesanBalasan //hook.params.message.text
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment