Using Glassix NPM Package on functions


The Glassix NPM package contains all the public Glassix API requests.

By importing the Glassix package to your function, you can easily use our REST API in your code.

Add the Glassix NPM Package

  1. Go to Settings.
    1. Click on the symbol in the agent dashboard.

  2. Click on DevelopersFunctions. Click here
  3. Click Add New Function.
  4. Fill Function Name and select Category, Type, and Timeout → Click Create.
  5. Connect the function to a chatbot flow or a Webhook.



Learn more about connecting your functions to a chatbot here or to a Webhook here.

  1. Switch to your function's Settings tab.
  2. Under the Import npm modules into your application section:
    1. In the Module text box, type glassix.
    2. Click Add
  3. Click Save.
  4. Define your clientOptions object



We recommend using environment variables for all theclientOptions parameters.


Tag a conversation based on message specific keywords

This example is for a function adding a tag when a message with specific keywords is sent. The function will be triggered when a new message is sent or received.

In this example, the keywords are "buy" or "purchase," and the tag added is "Sales".



In order to add a tag using a function the tag must be defined in the department settings. Click here to add tags to your department.

  1. Create a Function with Type Event.
  2. Import the Glassix NPM according to the instructions above.
  3. Click on Environment variables and create the following environment variables for your Access Token:
    1. API_KEY
    3. API_USER



To use it in-code, type process.env.YOURKEY.

  1. Link our newly created function to the "New Message" event. Read more about function events here.
  2. Copy and paste the following code
import * as glassix from "glassix";
* @param {Changes} changes
* @param {string} dateTime
* @param {string} key
const handler = async (changes, dateTime, key) => {
	try {
		//Create a glassix client
		const clientOptions = {
			workspace: process.env.WORKSPACE,
			apiKey: process.env.API_KEY,
			apiSecret: process.env.API_SECRET,
			userName: process.env.USER_NAME,
			domain: process.env.DOMAIN
		//Create the relevant tags
		const tags= ['Sales'];

		//Initiate glassix client
		const client= new glassix(clientOptions);

		//Use event from events array
		const change= changes[0];
		const isCorrectEvent = change._event === 'NEW_MESSAGE';

		// Checking if the event is 'New message' event and if the message contains any 'buy' or 'purchase'
		if (isCorrectEvent)
			if (change.transaction.text.includes('buy') || change.transaction.text.includes('purchase'))
			const ticketId = change.ticketId;
			const result = await, tags);
	} catch (error) {
  1. Let's test our function!