Alhena
  • Introduction
  • Getting Started
  • Architecture
  • Reference
    • Website SDK
      • Configure Proactive Nudges
    • Product FAQs
    • Website chatsdk events
    • Website chatsdk APIs
    • Chat SDK api and events examples
      • Open other external widget once human transfer is initiated
      • Show the Alhena AI widget only when someone scroll the page by 5 px
    • Website SDK - Custom data
      • Website SDK - Customer data with Agent
    • Website SDK - Internationalization
    • API Reference
      • API calls
    • Device Compatibility
  • Tutorials
    • AI Training
      • Training Steps
      • Training Data Sources
        • Websites
        • Youtube videos
        • Google Drive
        • Twitter Pages
        • Discord Messages
        • Confluence Pages
        • Upload Documents
        • Github
        • Zendesk Tickets
        • Freshdesk Tickets
        • Freshchat Tickets
        • Custom data sources
        • Shopify API
        • Woocommerce API
        • PDF Crawling
      • Training Frequently Asked Questions
    • Tuning Alhena AI Post Training
      • Best Practices for configuring the Alhena AI’s personality and guidelines
      • Adding Human Feedback for improving specific Questions
      • Adding to your knowledge base with FAQs
      • Frequently Asked Questions - Tuning Responses
    • QAing Al Conversations
      • Smart Flagging: Streamline Your AI Quality Assurance
    • Integrations
      • Alhena Website Chat SDK
        • Customizing Your Alhena Chat Widget
      • Integrating Alhena AI With Slack
      • Integrating Alhena AI With Discord
      • Integrating Alhena With Freshdesk
      • Integrating Alhena AI With Zendesk
      • Integrating Alhena AI With Email
      • Integrating Alhena AI With Shopify
      • Integration Alhena AI With Trustpilot
      • Integrating Alhena With Gorgias
    • Notifications
    • Alhena Dashboard
      • Managing Team
Powered by GitBook
On this page
  • Getting the Access token
  • Terminology
  • Send Message
  • send_message api returns the generate response given the user's query
  1. Reference
  2. API Reference

API calls

PreviousAPI ReferenceNextDevice Compatibility

Last updated 14 days ago

Alhena AI provides an API that allows developers to engage with their application (knowledge base hosted on Alhena). To obtain your API key, visit your account at app.alhena.ai/login and navigate to the bottom of the page.

Please note that this is only visible to our enterprize customers

Good to know: Please note that you need the api key only if you are try to use curl request to call Alhena AI services from your backend. For front end integration take a look at Website SDK

Getting the Access token

Access token can be created in developer api section

Important : API keys are visible once. If api key is lost then you need to create a new one.

Terminology

A user query is the question a customer enters and the developer sends to Alhena AI. An Alhena AI Response is what Alhena AI returns after a user query is submitted.

A thread is all user queries from a specific user and all associated Alhena AI responses. All user queries and Alhena AI responses that belong to a thread will have the same unique thread_id associated to them.

For example, the user queries and Alhena AI responses below are all one thread:

user: Hello

Alhena AI: How can I help you?

user: What is Gleen AI?

Alhena AI: A customer success product

How does thread_id work?

Alhena AI api has an optional parameter thread_id. When a given user ask first question then developer needs to pass empty or simple don't pass thread_id. In this case gleen ai return the response and generate the thread_id

For the next follow up conversation, developers need to pass the thread_id. By passing thread_id, developers intent to convey that this is a follow up message rather a new conversation

Alhena AI will return the thread_id in every response. If it's a new conversation then new thread_id is returned. If it is a follow up conversation then Alhena AI return the same thread_id

Send Message

Using send message api

send_message api returns the generate response given the user's query

POST https://api.alhena.ai/api/v1/send_message

send a query to alhena ai endpoint

Headers

Name
Type
Description

GLEENAI_API_KEY*

String

auth key for your gleen api

Request Body

Name
Type
Description

query_text*

string

query text sent to gleen ai for the response generation

thread_id

string

thread_id for the follow up conversation

{
    "thread_id"="802300",
    "conversation_id"="232312",
    "response": {
        "text": "Hello how can I help you?",
    }
}

Making requests VIA CURL

You can paste the command below into your terminal to run your first API request. Make sure to replace $GLEENAI_API_KEY with your secret API key.

curl https://api.alhena.ai/api/v1/send_message \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GLEEN_API_KEY" \
  -d '{
     "query_text": "What is the weather in celsius in San Francisco, CA?",
   }'

You should get a response back that resembles the following:

{
    "result_text": "I'm sorry, but as a text-based virtual assistant, I don't have the capability to execute functions or retrieve real-time data. However, you can use the `get_current_weather` function in your environment to get the current weather. Here's how you can use it:\n\n```javascript\nfunctions.get_current_weather({\n  location: \"San Francisco, CA\",\n  unit: \"celsius\"\n})\n```\n\nPlease replace `functions` with the actual namespace or object where the function resides in your environment.",
    "response_time": 12.15244152606465,
}

Making requests via python sdk

python installation

pip install gleenai

Setting up GLEENAI_API_KEY

gleenai.set_api_key("YOUR_API_KEY")

Sending requests

response = gleenai.send_message(
  query_text="YOUR_QUERY_TEXT", 
  thread_id="optional - Your thread from prevois call"
)

Sample response

'result_text': 'Sure, I\'d be happy to help. The Dockerfile you\'ve provided seems mostly correct, but there are a couple of potential issues that might be causing the build to fail.\n\n1. **Requirements File:** The `RUN pip install -r requirement.txt` command assumes that a file named `requirement.txt` exists in the `src` directory. If the file doesn\'t exist or is named differently (commonly it\'s named `requirements.txt`), this could cause the build to fail. Make sure the file exists and is correctly named.\n\n2. **CMD Syntax:** The CMD command should use double quotes ("") instead of single quotes (\'\'). This could be causing an issue.\n\nHere\'s an updated version of your Dockerfile:\n\n```Dockerfile\nFROM python:3.9\n\nWORKDIR /app\n\nCOPY src /app\n\nRUN pip install -r requirements.txt\n\nCMD ["python", "./app.py"]\n```\n\nPlease replace `requirements.txt` with your actual requirements file name if it\'s different. Also, ensure that `app.py` is present in the `src` directory. \n\nTry building the Docker image again with this updated Dockerfile. If you\'re still encountering issues, please provide the error message you\'re seeing during the build process for further assistance. \n\nHere is a [link](https://docs.docker.com/language/python/build-images/) that may be relevant.',
 'thread_id': 'c62614c9-ef57-4697-8105-f0c9a970bb13'}

Example - 1

query_text = "I recently attempted to build a Docker image using a Dockerfile, but the build process failed. I suspect there'\''s an issue with one of the commands in the Dockerfile, but I'\''m not sure how to resolve it. Can you help me update the Dockerfile to fix the build issue? Here is the dockerfile\n\n``` FROM python:3.9\n\nWORKDIR /app\n\nCOPY src /app\n\nRUN pip install -r requirement.txt\n\nCMD ['\''python'\'', '\''./app.py'\'']"
response = gleenai.send_message(query_text=query_text)

response is

{
 'result_text': 'Sure, I\'d be happy to help. The Dockerfile you\'ve provided seems mostly correct, but there are a couple of potential issues that might be causing the build to fail.\n\n1. **Requirements File:** The `RUN pip install -r requirement.txt` command assumes that a file named `requirement.txt` exists in the `src` directory. If the file doesn\'t exist or is named differently (commonly it\'s named `requirements.txt`), this could cause the build to fail. Make sure the file exists and is correctly named.\n\n2. **CMD Syntax:** The CMD command should use double quotes ("") instead of single quotes (\'\'). This could be causing an issue.\n\nHere\'s an updated version of your Dockerfile:\n\n```Dockerfile\nFROM python:3.9\n\nWORKDIR /app\n\nCOPY src /app\n\nRUN pip install -r requirements.txt\n\nCMD ["python", "./app.py"]\n```\n\nPlease replace `requirements.txt` with your actual requirements file name if it\'s different. Also, ensure that `app.py` is present in the `src` directory. \n\nTry building the Docker image again with this updated Dockerfile. If you\'re still encountering issues, please provide the error message you\'re seeing during the build process for further assistance. \n\nHere is a [link](https://docs.docker.com/language/python/build-images/) that may be relevant.',
 'thread_id': 'c62614c9-ef57-4697-8105-f0c9a970bb13'
}

https://
API Key generation for curl