Skip to content

The Ruby library for Kik Messenger's Bot API - from Robochy

License

Notifications You must be signed in to change notification settings

nimakaviani/rubychy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rubychy

rubychy

A ruby client for the Kik bot API provided by Robochy. 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.

With 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"
      )
   ]
)

link_message = Rubychy::DataTypes::Link.new(
 :url => 'http://robochy.com',
 :title => "Robochy", # Optional
 :to => "[RECIPIENT USERNAME]",
 :chatId => '[CHATID]'
)

text_message = Rubychy::DataTypes::Text.new(
 :body => 'Hello World!',
 :to => "[RECIPIENT USERNAME]",
 :chatId => '[CHATID]',
 :keyboards => keyboard
)

bot.send_message(link_message, text_message)

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, pass the received request to the ApiResponse.parse function:

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

About

The Ruby library for Kik Messenger's Bot API - from Robochy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages