Skip to content

Introduction

Stackchat's Dynamic Content SDK, available on npm as @stackchat/dynamic-content-toolkit provides helpful utilities to help you take advantage of full power of Cloud Functions.

This toolkit allows you to populate bot elements with dynamic content retreived from your organisation's owned resources at runtime.

Installation

  • npm
npm install @stackchat/dynamic-content-toolkit
  • yarn
yarn add @stackchat/dynamic-content-toolkit

Basics

Cloud Functions present an immensely wide array of possibilities customising and personalising interactions with your users. Before you get started on crafting the experience, you should keep a few things in mind:

  • Exported functions should always return an array of items.
  import { TextMessage } from "@stackchat/dynamic-content-toolkit"

  /** Valid */
  function sayHello() {
    return []
  }

  /** Valid */
  function sayHello() {
    const textMessage = new TextMessage()
    textMessage.text = "Hello, world!";

    return [ textMessage ]
  }

  /** Invalid */
  function sayHello() {
    return null;
    // return 4
    // return false
  }
  • Only exported functions are made available to the bot at run time

    You can create any number of functions, but only exported functions will be detected and made available to the bot for execution at run time.

  • Uploaded code must be plain JavaScript

    You can write your code in JavaScript, TypeScript or any other flavor of JS. You must ensure that you transpile and/or compile the code back to plain JavaScript so that it can be properly consumed by your bot.

    You can use Webpack or another bundling service to generate the code bundle, but the max file size for upload is limited to 5.8MB, so try to minimise the use of big third-party libraries.