{"id":19660671,"url":"https://github.com/vikdotdev/viberroo","last_synced_at":"2025-04-28T20:32:22.845Z","repository":{"id":48687092,"uuid":"249214707","full_name":"vikdotdev/viberroo","owner":"vikdotdev","description":"Viber bot on Ruby / Rails","archived":false,"fork":false,"pushed_at":"2025-01-07T12:26:58.000Z","size":84,"stargazers_count":10,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T02:02:56.532Z","etag":null,"topics":["rails","ruby","viber-api","viber-bot","webhooks"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/viberroo","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vikdotdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-22T15:38:37.000Z","updated_at":"2025-01-07T12:26:59.000Z","dependencies_parsed_at":"2025-01-07T13:27:03.586Z","dependency_job_id":"1153a987-37da-4d8c-be0e-a054a90dd990","html_url":"https://github.com/vikdotdev/viberroo","commit_stats":{"total_commits":58,"total_committers":3,"mean_commits":"19.333333333333332","dds":0.06896551724137934,"last_synced_commit":"b8556f678e2a84db9b4a7fd83e79c6e30fa59e98"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikdotdev%2Fviberroo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikdotdev%2Fviberroo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikdotdev%2Fviberroo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikdotdev%2Fviberroo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vikdotdev","download_url":"https://codeload.github.com/vikdotdev/viberroo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251383946,"owners_count":21580975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rails","ruby","viber-api","viber-bot","webhooks"],"created_at":"2024-11-11T16:04:51.093Z","updated_at":"2025-04-28T20:32:22.578Z","avatar_url":"https://github.com/vikdotdev.png","language":"Ruby","readme":"# Viberroo\nThis Viber bot is a thin wrapper for Viber REST API, written in Ruby. It uses mostly the same parameters as the official API, and provides a more readable alternative to explicit http requests.\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'viberroo', '~\u003e 0.3.4'\n```\n\nAnd then execute:\n```bash\n$ bundle install\n```\n\nOr install it yourself as:\n```bash\n$ gem install viberroo\n```\n\n## Usage\nFirst of all get acquainted with 'Getting Started' section on [Viber REST API page](https://developers.viber.com/docs/api/rest-bot-api/#get-started). There you'll find a link to create a bot. Read about webhooks in the relevant section and come back here to setup one for yourself.\n\n### Webhooks\nDuring webhook setup you need to specify an URL signed by known CA. NGrok is _the_ tool to help in such predicament - here's a [guide](https://developers.viber.com/blog/2017/05/24/test-your-bots-locally) on how to get started.\n\nRake task is good way of managing webhooks:\n```bash\n$ rails g task viber set_webhook remove_webhook\n```\n```ruby\n  # lib/tasks/viber.rake\n  namespace :viber do\n    task set_webhook: :environment do\n      Viberroo::Bot.new.set_webhook(\n        url: 'https://\u003cyour_ngrok_public_address\u003e/viber',\n        event_types: %w[conversation_started subscribed unsubscribed],\n        send_name: true,\n        send_photo: true\n      )\n    end\n\n    task remove_webhook: :environment do\n      Viberroo::Bot.new.remove_webhook\n    end\n  end\n```\nWe won't run our task just yet - during task execution API will make a callback request to our server to make sure it exists, and we'll need to handle that first. Also you'll need to provide your Viber API token:\n```ruby\n# config/initializers/viberroo.rb\n\nViberroo.configure do |config|\n  config.auth_token = '\u003cyour_viber_bot_api_token\u003e'\nend\n```\n\n### Controller\nGenerate a controller with `rails g controller viber callback` and point a route to it:\n```ruby\n# config/routes.rb\n\npost '/viber' =\u003e 'viber#callback'\n```\n\n```ruby\n# app/controllers/viber_controller.rb\n\nclass ViberController \u003c ApplicationController\n  skip_before_action :verify_authenticity_token\n\n  def callback\n    @response = Viberroo::Response.new(params.permit!)\n    @bot = Viberroo::Bot.new(response: @response)\n\n    head :ok\n  end\nend\n```\nNote that `params.permit!` is necessary to form a correct `Response` object.\n\nAt this point running `set_webhook` task should return `{ \"status\":0, \"status_message\":\"ok\", ... }`:\n```bash\n$ rake viber:set_webhook\n```\n\nFrom here we can fork the flow of execution based on event type as shown in `handle_event` method. For example when event type is 'message', we can fork the flow based on message text as shown in `handle_message` method. More information on callback events can be found in 'Callbacks' section in [API Documentation](https://developers.viber.com/docs/api/rest-bot-api/#callbacks)\n```ruby\n  # app/controllers/viber_controller.rb\n  # ...\n\n  def callback\n    # ...\n    handle_event\n\n    head :ok\n  end\n\n  private\n\n  def handle_event\n    case @response.params.event\n    when 'message'\n      handle_message\n    when 'conversation_started'\n      greet_user\n    end\n  end\n\n  def handle_message\n    case @response.params.message.text\n    when '/start'\n      choose_action\n    when '/help'\n      display_help\n    end\n  end\n\n  def greet_user\n    message = Viberroo::Message.plain(text: 'Hello there! Type /start to get started.')\n    @bot.send(message: message)\n  end\n```\n\nTo respond back to the user `Viberroo::Bot` class is equipped with `send` method which accepts various [message types](https://developers.viber.com/docs/api/rest-bot-api/#message-types). See _method name/message type_ mapping in [documentation](#documentation).\n```ruby\n  # app/controllers/viber_controller.rb\n\n  # ...\n\n  def display_help\n    message = Viberroo::Message.plain(text: 'Type /start to get started!')\n    @bot.send(message: message)\n  end\n```\n\nThe Viber API allows sending a custom keyboard with predefined replies or actions. Such a keyboard can be attached to any message:\n```ruby\n  # app/controllers/viber_controller.rb\n  class ViberController \u003c ApplicationController\n    include Viberroo\n\n    # ...\n\n    def choose_action\n      something = Input.reply_button({\n        Columns: 3,\n        Rows: 2,\n        Text: 'Do Something',\n        ActionBody: '/some_text_to_trigger_message_case'\n      })\n\n      google = Input.url_button({\n        Columns: 3,\n        Rows: 2,\n        Text: 'Go to google',\n        ActionBody: 'google.com'\n      })\n\n      message = Message.plain(text: 'What would you like to do?')\n      keyboard = Input.keyboard(Buttons: [something, google])\n      @bot.send(message: message, keyboard: keyboard)\n    end\n  end\n```\n\nEach buttons' `ActionType` has a corresponding method inside `Viberroo::Input` module. `keyboard` method also comes from there. See Viber API [Button parameters](https://viber.github.io/docs/tools/keyboards/#buttons-parameters) section for parameter explanation and possibilities.\n\n## Documentation\nDocumentation can be found on [rubygems](https://www.rubydoc.info/gems/viberroo/Viberroo), or generated locally by cloning the repository and running `yard` in the root of the project.\n\n## Development\nAfter checking out the repository, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, create a tag\nfor a new version, and then merge to master, GitHub actions will take care of running specs and pushing to [rubygems.org](https://rubygems.org).\n\n\n## Contributing\nBug reports and pull requests are welcome on GitHub at https://github.com/vikdotdev/viberroo.\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvikdotdev%2Fviberroo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvikdotdev%2Fviberroo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvikdotdev%2Fviberroo/lists"}