rubychy
A ruby client for the Kik bot API
The rubychy library borrows heavily from the Telegrammer API, developed by Luis Mayoral
Installation
Add the gem to your application's Gemfile
gem 'rubychy'
and run the following
$ bundle install
Usage
Create a bot using the Kik developer portal. Upon registration, you will get to choose a username
for your bot. Once the username
is created navigate to the bot configuration dashboard where you can find the API Key
.
Witht your bot username
and the API Key
you can use rubychy
like the following:
require 'rubychy'
bot = Rubychy::Bot.new('[BOT USERNAME]', '[API KEY]')
If you need to register a callback
for your bot, do it by calling config
:
bot.config('[HTTPS CALLBACK URL]')
You can also customize the configuration features by passing the features into the config function:
bot.config('[HTTPS CALLBACK URL]', Rubychy::DataTypes::Features.new([YOUR CONFIG]))
Sending Messages
With a created bot you can create messages of different types, attach custom keyboards, and pass them through the send_message
function as follows:
require 'rubychy'
bot = Rubychy::Bot.new('[BOT USERNAME]', '[API KEY]')
keyboard = Rubychy::DataTypes::Keyboard.new(
:to => '[RECIPIENT USERNAME]',
:hidden => true,
:responses => [
Rubychy::DataTypes::KeyboardResponse.new(
type: "text",
body: "hi"
),
Rubychy::DataTypes::KeyboardResponse.new(
type: "text",
body: "bye"
)
]
)
= Rubychy::DataTypes::Link.new(
:url => 'http://robochy.com',
:title => "Robochy", # Optional
:to => "[RECIPIENT USERNAME]",
:chatId => '[CHATID]'
)
= Rubychy::DataTypes::Text.new(
:body => 'Hello World!',
:to => "[RECIPIENT USERNAME]",
:chatId => '[CHATID]',
:keyboards => keyboard
)
bot.(, )
Rubychy supports the existing data types for Kik. Refer to the library for the details.
Getting User Information
require 'rubychy'
bot = Rubychy::Bot.new('[BOT USERNAME]', '[API KEY]')
user_info = bot.get_user('[TARGET USERNAME]') # user_info is of type Rubychy::DataTypes::User
Parsing the Response
In your callback servlet:
class Simple < WEBrick::HTTPServlet::AbstractServlet
def do_POST(request, response)
kik_response = Rubychy::ApiResponse.parse(request) # kik_response is of type Rubychy::DataTypes::ReceivedMessages
end
end
Contributing
- Fork it: https://github.com/nkaviani/rubychy/fork
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request