How To Create an Echo Bot with Kik
I know you’re interested in bots because you’re reading this.
According to Wikipedia, Kik is an instant messenger application (app) for mobile devices from Kik Interactive, available free of charge on iOS, Android, and Windows Phone operating systems.
Kik lets you connect with friends, groups and the world around you through chat. And now, you can chat with bots too.www.kik.com
Kik has a Bot Shop.
Let me introduce you how to create an echo bot with Kik. First, please prepare following items to create Kik. In this case, everything is for Mac because I don’t have PC. So, this means that if you’re using PC(Windows), please search what you need.
Mac/PC (Doesn’t matter a laptop or desktop)
NodeJS (Javascript for serverside)
https://nodejs.org/en/
In my case, I used v5.4.1 to make a bot.
npm (package manager for nodejs)
https://www.npmjs.com/
Editor (What you want)
iTerm/Terminal/Command Prompt
ngrok
ngrok is a nice tool which allows users to publish your localhost safely.
That means when you start your local server and ngrok, people who know a specific url that is provided by ngrok can access what you want to publish.
https://ngrok.com/
Kik account
Read this url(https://dev.kik.com/#/docs/getting-started) to make your account.
Step1. Init
$ npm init
If you don’t know what terminal is talking about, just hit return key a few times.
Step2. Install packages
$ npm install @kikinteractive/kik — save
$ npm install util — save
Step3. create index.js
copy the codes from https://www.npmjs.com/package/@kikinteractive/kik
Here is code
‘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: ‘your bot name’,
apiKey: ‘your api key’,
baseUrl: ‘your ngrok url'
});
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 || 8080);
Step4. Start ngrok
First put a ngrok you downloaded in your bot folder. Then type the following command.
$ ./ngrok http 8080
Why we should type “8080" is to fit the codes.
After this, you can get links like the following.
Forwarding http://f70bbd27.ngrok.io -> localhost:8080
Forwarding https://f70bbd27.ngrok.io -> localhost:8080
In this case, we only need https.
Step5. Change Code(a little bit)
Copy what you get the link from ngrok and paste it on your code.
I mean paste the url on “your ngrok url”.
Step6. start server
Finally, we will start our server. Move into your bot folder by using cd command. Then type below.
$ node index.js
Step.7 Type something to your bot
Here is more information about kik package.
If you get some problems, please let me know by comments.
Hope you enjoy your kik bot.