username: '******', apiKey: '162091ee-2785-4af4-b833-91dda5356ff9', baseUrl: 'https://wyrz.herokuapp.com/' } brain = new Brain() bot = new Bot(configuration.kik) app = express() httpd = http.createServer() io = Socket(httpd) bot.updateBotConfiguration() bot.onTextMessage(it => { it.reply(it.body) io.emit('message', it.body) }) app.use(express.static('public')) httpd.on('request', (request, response) => { bot.incoming().call(httpd, request, response) if (request.url.indexOf('/incoming') === -1 && request.url.indexOf('/socket.io') === -1) { app.call(httpd, request, response) } }) httpd.listen(process.env.PORT || 8080, function () { console.log(httpd.address().port, httpd.remoteAddress) })
bot.onTextMessage((message) => { var text = message.body; var from = message.from; console.log('Received: \"' + text + '\" from ' + from); // conversationHandler.handleIncomingMessage(message); // find the conversation trigger for(var i=0; i<tree.messages.length; i++ ){ if( text.match(RegExp(tree.messages[i].keywords, 'i')) ){ // conversation trigger found console.log("from1: " + from); var messageId = i; console.log (tree.messages[messageId].keywords + ' matched for: ' + text); if( tree.messages[messageId].type == 'text'){ message.setBody(tree.messages[messageId].text); } else if( tree.messages[messageId].type == 'picture'){ var from = message.from; message = Bot.Message.picture(tree.messages[messageId].url) // .setText(tree.messages[messageId].text != '' ? tree.messages[messageId].text : '') .setAttributionName('Click me') .setAttributionIcon('http://www1.macys.com/favicon.ico'); if(tree.messages[messageId].text != ' '){ bot.send(message, from); message = Bot.Message.text(tree.messages[messageId].text); } } else if( tree.messages[messageId].type == 'video' || tree.messages[messageId].type == 'link' ){ var from = message.from; message = Bot.Message.link(tree.messages[messageId].url) .setText(tree.messages[messageId].text != '' ? tree.messages[messageId].text : '') .setAttributionName('Click me') .setAttributionIcon('http://www1.macys.com/favicon.ico'); } var buttons = []; for(var j=0; j<tree.messages[messageId].buttons.length; j++){ buttons.push(tree.messages[messageId].buttons[j].text); } message.addTextResponse(buttons); console.log("from2: " + from + '\n'); bot.send(message, from); }else{ // console.log(tree.messages[i].keywords + ' not matched'); } } });
bot.onStartChattingMessage((message) => { bot.getUserProfile(message.from).then((user) => { message.reply(`Hi ${user.firstName}! I can send you sounds or tell you more about FoundSounds!`); message.addResponseKeyboard(options, true); }); }); bot.onTextMessage((message) => { var myMessage = Bot.Message if (message.body == "Recent sound") { mixpanel.track('recent_sound'); sendRecent(message.from); } else if (message.body == "Random sound") { mixpanel.track('random_sound'); sendRandom(message.from); } else if (message.body == "Learn more") { mixpanel.track('learn_more'); myMessage = myMessage.text("I'm so happy you want to learn more about FoundSounds! I am a bot."); sendInfo(message.from); } else { sendGeneric(message.from); } }); bot.onLinkMessage((message) => { sendGeneric(message.from); }); bot.onPictureMessage((message) => { sendGeneric(message.from);
user.state = user.state+1 } ///Ivar emoji test // console.log("Hello Ivar") // outgoingMessage = Bot.Message.text('\ud83d\ude0d') user.save()//save the user bot.send(outgoingMessage, message.from)}) }//end allLogic //onMessage Types============================================= bot.onTextMessage((message) => { //Needed to create variable for the Outgoing Message allLogic(message) }); //end bot.onTextMessage((message) => bot.onPictureMessage((message)=> { allLogic(message) }); bot.onVideoMessage((message)=> { allLogic(message) }); bot.onStickerMessage((message)=> { allLogic(message) });
bot.onTextMessage((message) => { // we will use the Kik username as our session id when we post to the zork API var session_from = message.from; var log_arguments = ["Message Received from: ", session_from]; logFile.write(util.format.apply(null, log_arguments) + '\n') // the following commands is needed for multi-word commands with spaces var command = message.body.split(' ').join('+'); var log_arguments = ["Command is",command]; logFile.write(util.format.apply(null, log_arguments) + '\n') if (session_from == 'somerandomguy638') { message.reply('Should you be studying, Taka?'); } if (session_from == 'zafra42') { message.reply('How is the coop?'); } // custom message in order to provide help if ((message.body == 'help') || (message.body == 'Help') || (message.body == 'H') || (message.body == 'h')) { message.reply('Zork accepts a surpisingly wide set of commands including directions such as \'south\' and verbs like \'take\' and \'inventory\'. Direct objects are usually accepted.'); message.reply('A list of Zork commands is available at http://zork.wikia.com/wiki/Command_List'); } //there is a title, a locatiom, and a message returned from JSON //this following variable holds the message var tlefResponse_message; var currLocation; // Create the URL to return the Zork command var zork_url = "https://tlef.ca/projects/restful-frotz/?play&data_id=zork1&session_id="+ session_from + "&command=" + command + "&output-webhook=" + bot.baseUrl; log_arguments = ["URLs is ",zork_url]; logFile.write(util.format.apply(null, log_arguments) + '\n') var body = ''; // Get the response from the Zork API https.get(zork_url, function(res){ //var req = http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function(chunk){ console.log('BODY: ' + chunk); body += chunk; }); res.on('end', function(){ var tlefResponse = JSON.parse(body); if (tlefResponse.location != null) { //if (tlefResponse.location != currLocation) { message.reply(tlefResponse.location); //} currLocation = tlefResponse.location; } //sometimtes the title and location are the same, in which case we don't want to say the same thing twice if ((tlefResponse.title !== null) && (tlefResponse.title !== tlefResponse.location)) { message.reply(tlefResponse.title); } if ((tlefResponse.message !== undefined) && (tlefResponse.message !== "")) { // End of line \n were giving problems so parsed them out tlefResponse_message = tlefResponse.message.replace(/(\r\n|\n|\r)/gm,""); //console.log("tlefResponse_message body is " + tlefResponse_message); message.reply(tlefResponse_message); } var current_loc_message = "User " + message.from + " is presently in " + currLocation; var log_arguments = [current_loc_message]; logFile.write(util.format.apply(null, log_arguments) + '\n'); console.log(current_loc_message); }); }).on('error', function(e){ console.log("Got an error: ", e); }); });
username: process.env.KIK_USERNAME, apiKey: process.env.KIK_API_KEY, baseUrl: process.env.KIK_BASE_URL, receiveReadReceipts: true, receiveDeliveryReceipts: true }); bot.updateBotConfiguration(); //configure dashbot for the bot dashbot.configHandler(bot); //set dashbot handler bot.use(dashbot.logHandler); bot.onTextMessage(function(message) { message.reply('You are right when you say: ' + message.body); }); bot.onLinkMessage(function(message, next) { message.reply('Thank you for the link'); }); bot.onPictureMessage(function(message, next) { message.reply('Thank you for the image'); }); bot.onVideoMessage(function(message, next) { message.reply('Thank you for the video'); }); bot.onStartChattingMessage(function(message, next) {
}); bot.updateBotConfiguration(); // Track incoming messages bot.use((message, next) => { dialog.incomingMiddleware(message, next); }) // Track outgoing messages bot.outgoing((message, next) => { dialog.outgoingMiddleware(message, next); }); bot.onTextMessage((message) => { var replies = ["Hey, ho!", "Let's go!"]; bot.send(replies, message.from, message.chatId); }); bot.onPictureMessage((message) => { bot.send(Bot.Message.picture('http://i.imgur.com/oalyVlU.jpg') .setAttributionName('Imgur') .setAttributionIcon('http://s.imgur.com/images/favicon-96x96.png'), message.from, message.chatId); }); // Set up your server and start listening let server = http .createServer(bot.incoming()) .listen(process.env.PORT || 8080);
console.log(a.join('')); return a.join(""); }; bot.onStartChattingMessage((msg) => { console.log(msg); msg.reply('Hello ' + msg.from + ', give me an input and I will tell you if it\'s 13'); }); bot.onTextMessage((msg) => { var body = msg.body.toLowerCase(); if (is(body).thirteen()) { msg.reply(choose(strings.isThirteen)); } else if (is(body).roughly.thirteen()) { msg.reply(choose(strings.isRoughlyThirteen)); } else if (is(body).square.of.thirteen()) { msg.reply('Good news! ' + body + ' ' + choose(strings.isSquareOfThirteen)); } else if (is(body).divisible.by.thirteen()) { msg.reply(choose(strings.isNotThirteen) + ' However, ' + body + ' ' + choose(strings.isDivisibleByThirteen).toLowerCase()); } else if (is(body).backwards.thirteen()) { msg.reply(choose(strings.isBackwardsOfThirteen)); } else if (is(body).anagramOf.thirteen()) { msg.reply('thirteen'.shuffle() + ', see ' + choose(strings.isAnagramOfThirteen)); } else { msg.reply(choose(strings.isNotThirteen)); } }); module.exports = bot;
'use strict'; let util = require('util'); let http = require('http'); let Bot = require('@kikinteractive/kik'); // Configure the bot API endpoint, details for your bot let bot = new Bot({ username: '******', apiKey: '552749d9-1b6b-4ae5-903d-bb07c812aa59', baseUrl: 'https://kik-echobot.ngrok.io/' }); bot.updateBotConfiguration(); bot.onTextMessage((message) => { message.reply(message.body); }); // Set up your server and start listening let server = http .createServer(bot.incoming()) .listen(process.env.PORT || 3000);
}); // This is a middleware statement and needs to stay here and not be rearranged. bot.updateBotConfiguration(); // This is the first text message handler. The logic for handling bot messages // is you either reply() or call next() to go to the next handler in the chain. // They are called sequentially so we have a catch-all at the end if the // message is not part of the grammar. bot.onTextMessage((message, next) => { // Check that it's an authenticated user (only need to check on first message) if (users.isUser(message.from)) { logger.info('Received a bot message from ' + message.from); if (message.type == 'text') { next(); } else { message.reply('Text messages only, please'); } } else { message.reply('Unauthorized'); logger.info('Unauthorized user: '******'meals') == 0) { metrics.recordEvent('meals', 'request', 'success', 1, message.from); users.getMealsForUser(message, function(meals) { message.reply('Meals are: ' + meals); }); } else {