Project

rubychy

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby client for the Kik Bot API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.1

Runtime

~> 1.11
~> 1.0
 Project Readme
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