crisp-im / ruby-crisp-api

πŸ’Ž Crisp API Ruby Wrapper
https://docs.crisp.chat/guides/rest-api/
MIT License
16 stars 7 forks source link

Crisp API Wrapper

Build and Release RubyGems Downloads

The Crisp API Ruby wrapper. Authenticate, send messages, fetch conversations, access your agent accounts from your Ruby code.

Copyright 2023 Crisp IM SAS. See LICENSE for copying information.

Usage

You may follow the REST API Quickstart guide, which will get you running with the REST API in minutes.

Add the library to your Gemfile:

gem "crisp-api", "~> 1.1.12"

Then, import it:

require "crisp-api"

Build a new authenticated Crisp client with your identifier and key tokens.

client = Crisp::Client.new

client.set_tier("plugin")
client.authenticate(identifier, key)

Then, your client is ready to be consumed!

Authentication

To authenticate against the API, obtain your authentication token keypair by following the REST API Authentication guide. You'll get a token keypair made of 2 values.

Keep your token keypair values private, and store them safely for long-term use.

Then, add authentication parameters to your client instance right after you create it:

client = Crisp::Client.new

# Authenticate to API with your plugin token (identifier, key)
# eg. client.authenticate("5c0595b2-9381-4a76-a2e0-04aa00c1ede7", "3bdb0812d0f5352bf68901ddc731434dade419b98507971905acdd2f967df61c")
client.set_tier("plugin")
client.authenticate(identifier, key)

# Now, you can use authenticated API sections.

Resource Methods

Most useful available Crisp API resources are implemented. Programmatic methods names are named after their label name in the REST API Reference.

All methods that you will most likely need when building a Crisp integration are prefixed with a star symbol (⭐).

In the following method prototypes, crisp is to be replaced with your Crisp API instance. For example, instanciate client = Crisp() and then call eg: client.website.list_conversations(website_id, 1).

When calling a method that writes data to the API (eg. send a message with: client.website.send_message_in_conversation()), you need to submit it this way:

website_id = "6497e4a4-b17c-41e0-bfea-eea97ba8115a"
session_id = "session_f32bc993-f7ce-41af-bcd1-110fc147a392"

client.website.send_message_in_conversation(
  website_id, session_id,

  {
    "type" => "text",
    "content" => "This message was sent from ruby-crisp-api! :)",
    "from" => "operator",
    "origin" => "chat"
  }
)

⚠️ Note that, depending on your authentication token tier, which is either user or plugin, you may not be allowed to use all methods from the library. When in doubt, refer to the library method descriptions below. Most likely, you are using a plugin token.

Website

πŸ‘‰ Notice: The peopleID argument can be an email or the peopleID.

Bucket