Create a ChatGPT Slash Command in Zoho Cliq

02.25.23 11:03 AM By Andy

What we are going to do

In this tutorial we are going to go over how to create a slash command in Zoho Cliq, so you can ask questions to ChatGPT directly in Cliq. Once you get the answer, you will be able to post them on any chat or channel. We are going to use the ChatGPT-3 API, that is not the latest version. The ChatGPT-4 API is not available at the time of creating this tutorial. Once the newer API version is available, we will edit this article.

Pre-requisites

  • An OpenAI account.

Creating the Command

  1. In Zoho Cliq, click on your profile picture, and go to "Bots & Tools".
  2. On the left, click on "Commands"
  3. Click on the "Create Command" button
  4. Name the command: for this example we are going to name it "chatgpt"
  5. Add a Hint: for example, ChatGPT answers your questions.
  6. Choose the access level: we are going to choose "organization"
  7. Optional: add an image
  8. Click on "Save & Edit Code"

Editing the Code

On the Execution Handler tab:
  1. Delete the code that is already there.
  2. Copy the code below.
  3. Paste the code in the "Execution Handler" tab.
  4. In OpenAI account, go to the settings and click on the "API Keys" tab (or use this link).
  5. Generate a new secret key and copy it.
  6. Back in Zoho Cliq, replace the key "XXXXXXXXXXXX" with the one you generated.
  7. Cliq on Save.

On the Suggestion Handler tab:
  1. Remove the code.
  2. Click on Save

Testing the Command

  1. Open a chat or channel in Zoho Cliq
  2. Tipe /chatgpt and press Enter
  3. The first time you use the Command, you will have to allow the Command to access certain information. Click on "Proceed to Allow".
  4. Type a prompt. For example, "what is Zoho Cliq?".
  5. Press enter to send the message.
  6. The Command responded to you. The message is visible to you only.
  7. Use one of the options for the message: post it on the chat, forward it to other chats or channels, or close it. If you don't choose any of the options, when you close the chat, the message will be closed automatically.

Code

response = Map();
// Creating the card
card = Map();
card.put("theme","modern-inline");
card.put("title","ChatGTP");
// Add Open AI token
token = "Bearer XXXXXXXXXXXX";
//
header = Map();
header.put("Authorization",token);
header.put("Content-Type","application/json");
params = {"model":"text-davinci-003","prompt":arguments,"temperature":0.4,"top_p":1,"max_tokens":256,"frequency_penalty":0,"presence_penalty":0,"stop":{" Human:"," AI:"}};
fetchCompletions = invokeurl
[
url :"https://api.openai.com/v1/completions"
type :POST
parameters:params.toString()
headers:header
detailed:true
];
info "Fetch completions: " + fetchCompletions;
if(fetchCompletions.get("responseCode") == 200)
{
answer = fetchCompletions.get("responseText").get("choices").getJSON("text");
response.put("text",answer);
}
else if(fetchCompletions.get("responseCode") == 429)
{
response = {"text":"Oops! I can't help with this. Try asking something else :wink:"};
}
// Adding response to the card
response.put("card",card);
//
return response;