crisp-im / python-crisp-api

🐍 Crisp API Python Wrapper
https://docs.crisp.chat/guides/rest-api/
MIT License
27 stars 11 forks source link

Crisp API Wrapper

Build and Release PyPI Downloads

The Crisp API Python wrapper. Authenticate, send messages, fetch conversations, access your agent accounts from your Python 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.

Install the library:

pip install crisp-api

Then, import it:

from crisp_api import Crisp

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

client = Crisp()

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()

# Authenticate to API with your plugin token (identifier, key)
# eg. client.authenticate("13937834-f6ce-4556-ae4f-9e0c54faf038", "eb6c3623245521d7a6c35f5b29f3fa756e893f034ed551d84518961c5ff16dec")
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 = "88972681-a00c-4b3b-a383-cab281636484"
session_id = "session_9df2a21e-f113-41d4-8ed2-bad8b49cafd1"

client.website.send_message_in_conversation(
  website_id, session_id,

  {
    "type": "text",
    "content": "This message was sent from python-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.

Plugin

Bucket