Skip to content
On this page

Vanilla textarea example

This example assumes you have a Deepdesk account and the webhook and SSO are configured.

Html example:

html
<form id="form">
  <textarea id="input"></textarea>
  <button type="submit">Submit</button>
</form>

Javascript example:

js
import "@deepdesk/deepdesk-sdk/styles";
import { DeepdeskSDK, updateTextArea } from "@deepdesk/deepdesk-sdk";

const formElement = document.getElementById("form");
const inputElement = document.getElementById("input");
const deepdeskSDK = new DeepdeskSDK({
    deepdeskUrl: "https://<accountname>.deepdesk.com",
});

const isSupported = await deepdeskSDK.isConversationSupported("123", {
    attempts: 5,
    retryDelay: 500,
});

if (!isSupported) return;

deepdeskSDK.mount(inputElement);

deepdeskSDK.login().then(async () => {
    // Get conversation by platform caseId/conversationId/sessionId
    deepdeskSDK.getConversationBySessionId("123");

    deepdeskSDK.setVisitorInfo({
        visitorName: "Anne",
    });

    deepdeskSDK.setAgentInfo({
        agentName: "Sam de Pam",
        agentNickname: "Sam",
    });

    deepdeskSDK.on("select-suggestion", ({ text, replace }) => {
        updateTextArea(inputElement, text, {
            replace,
        });
    });

    deepdeskSDK.on("replace", ({ text, replace }) => {
        updateTextArea(textareaEl, text, {
            replace,
        });
    });

    deepdeskSDK.on("reset", ({ text, selectionAfter }) => {
        updateTextArea(textareaEl, text, {
            selectionAfter,
        });
    });

    formElement.addEventListener("submit", async (event) => {
        await sendMessageToYourBackend(); // Handle your platform submit logic ...

        deepdeskSDK.notifySubmit({ sentText: inputElement.value });
        inputElement.value = "";

        await deepdeskSDK.refresh();
    });
});