npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mb-sdk

v1.0.20

Published

Mindbehind SDK

Downloads

39

Readme

Mindbehind SDK

Description

This SDK is a client library designed to facilitate the usage of Mindbehind company's message components. It provides an easy-to-use interface for creating modules and sending messages, enabling seamless integration with the Mindbehind platform. With this SDK, our collaborators can leverage the power of Mindbehind's messaging features to enhance their applications and streamline communication with their users.


Installation

To use the SDK, ensure that Node.js and npm are installed. Follow the steps below to include the SDK in your project:

npm install mb-sdk

or

yarn add mb-sdk

Usage

Generic Platform

Basic Example

import { Client, PlatformGeneric } from "mb-sdk";

// Create new ChatBot Client
const client = new Client.ChatBotClient(
	{
		baseURL: "", // mindbehind base url
	},
	{
		channelId: "", // channel id from management token on channel tabs
		managementToken: "", // management token from management token on channel tabs
	}
);

// Create new Message module
const message = new PlatformGeneric.TextMessage({ content: "Hello" });

// Send message module with client send function
await client.send(message);

Integration Platform

Basic Example

iimport { PlatformIntegration } from "mb-sdk";

// Create new Message module
const message = new PlatformIntegration.TextMessage({ payloads: ["Hello"] });

// Build response model
const responseData = new PlatformIntegration.IntegrationResponse({
	modules: [message],
	params: { name: "Henlo" },
}).buildStringfy();

return {
	statusCode: 200,
	body: responseData,
};

BaseModule

The BaseModule class is an abstract class that serves as the foundation for creating different modules in a system. It provides common functionality and fields that can be extended and customized by specific module implementations. All other modules are derived from the BaseModule. They share the same fields, but the types of these fields may vary depending on the module. This inheritance ensures a consistent structure across modules while allowing flexibility in defining specific field types.

Constructor

Parameters

  • params (BaseModuleConstructorParams): An object containing the configuration parameters for the module.

Properties

  • type (TModuleType): The type of the module. Every module must have a type, which determines the behavior and available fields of the module.
  • delay (number, optional): The delay duration of the module in milliseconds. Defaults to undefined.
  • payloads (Array<any>, optional): An array where the module payloads are located. This field allows the configuration of the output structure. Defaults to undefined.
  • connections (Array<TConnectionType>, optional): An array used to manage and direct node connections. Defaults to undefined.
  • fallback (number, optional): The target node ID to go to when there is an error on the module. Defaults to undefined.
  • fallbackCount (number, optional): The number of accepted wrong answers. The default value is 0.
  • errorMessage (string, optional): The message to be sent when a wrong answer is received. Defaults to undefined.
  • inputParam (string, optional): The parameter name to which the input will be recorded. Defaults to undefined.

Methods

  • valid(): Performs validation checks on the module's properties. Throws an InvalidPayloadError if any validation fails.

Validation Rules

The BaseModule class enforces the following validation rules on its properties:

  • payloads: Must be an array if defined.
  • fallback: Must be a valid positive number if defined.
  • fallbackCount: Must be a positive number between 0 and 9 if defined.
  • delay: Must be a valid positive number between 0 and 84600 (number of seconds in a day) if defined.
  • connections: Must be an array if defined.
  • inputParam: Must be a non-empty string if defined.

These validation rules ensure that the module's properties are set correctly and conform to the expected data types and constraints.


Modules

Below is a list of modules used in Mindbehind along with their descriptions:

Message Module

Text Message

The Text Message module allows sending text-based messages to users. It is commonly used to deliver textual information or engage in conversational interactions with users.

Usage

import { PlatformIntegration } from "mb-sdk";

const exampleTextMessage = new PlatformIntegration.TextMessage({
	payloads: ["test"],
	delay: 1000,
});

Audio Message

The Audio Message module enables sending audio files or voice recordings as messages to users. It is useful for sharing audio content or providing voice-based interactions.

Usage

import { PlatformIntegration } from "mb-sdk";

const exampleAudioMessage = new PlatformIntegration.AudioMessage({
	payloads: ["www.unkowndomain.com/example.mp3"],
	delay: 1000,
});

File Message

The File Message module allows sending various types of files, such as documents, PDFs, or spreadsheets, to users. It provides a convenient way to share files within the conversation.

Usage

import { PlatformIntegration } from "mb-sdk";

const exampleFileMessage = new PlatformIntegration.FileMessage({
	payloads: ["www.unkowndomain.com/example.pdf"],
	delay: 1000,
});

Image Message

The Image Message module enables sending image files or visual content to users. It is commonly used to share pictures, graphics, or any other visual media within the conversation.

Usage

import { PlatformIntegration } from "mb-sdk";

const exampleImageMessage = new PlatformIntegration.ImageMessage({
	payloads: ["www.unkowndomain.com/example.png"],
	delay: 1000,
});

Video Message

The Video Message module allows sending video files or multimedia content to users. It provides a means to share videos or engage in video-based interactions within the conversation.

Usage

import { PlatformIntegration } from "mb-sdk";

const exampleVideoMessage = new PlatformIntegration.VideoMessage({
	payloads: ["www.unkowndomain.com/example.mp4"],
	delay: 1000,
});

Selection Module

Selection modules enable interactive communication by prompting users with choices and waiting for their actions. If you wish to ask multiple-choice questions or provide selectable options, these modules are the perfect choice. With their help, you can effortlessly engage users in decision-making processes and capture their selections, enhancing the overall user experience.

Card Message

Card Message is a versatile message format that allows you to send visually appealing content to users. It includes images, buttons, text, and titles to prompt user interaction and decision-making

Usage

import { PlatformIntegration } from "mb-sdk";

const carButton = new PlatformIntegration.TextButton({ text: "Car", action: "Car", value: 20 });
const bikeButton = new PlatformIntegration.TextButton({ text: "Bike", action: "Bike", value: 21 });
const otherButton = new PlatformIntegration.TextButton({ text: "Other", action: "Other", value: 22 });

const card = new PlatformIntegration.ChatBotCard({
	title: "Question 1",
	text: "What mode of transportation would you like to use?",
	image: "www.blabla.com/example.jpg",
	buttons: [carButton, bikeButton, otherButton],
});

const cardMessage = new PlatformIntegration.CardMessage({
	delay: 250,
	payloads: [card],
	fallback: 20,
	fallbackCount: 3,
	inputParam: "transportationAnswer",
	errorMessage: "Please check your answer.",
});

Quick Reply Message

Quick Reply Message refers to a type of interactive message that allows users to choose from a predefined set of options as a response. It typically appears as a list of buttons or selectable options, enabling users to quickly select their desired response instead of typing it out. Quick Reply Messages provide a more streamlined and user-friendly way of engaging with a conversation or interactive system, making it easier for users to provide input or navigate through available choices.

Usage

import { PlatformIntegration } from "mb-sdk";

const carButton = new PlatformIntegration.TextButton({ text: "Car", action: "Car", value: 20 });
const bikeButton = new PlatformIntegration.TextButton({ text: "Bike", action: "Bike", value: 21 });
const otherButton = new PlatformIntegration.TextButton({ text: "Other", action: "Other", value: 22 });

const qrMessage = new PlatformIntegration.QuickReplyMessage({
	delay: 250,
	payloads: [carButton, bikeButton, otherButton],
	prompt: "Prompt",
	fallback: 20,
	fallbackCount: 3,
	inputParam: "transportationAnswer",
	errorMessage: "Please check your answer.",
});

List Message

List Message is a message format that presents information in a structured list format. It includes sections and rows, allowing you to organize and display content in a categorized manner.

Usage

import { PlatformIntegration } from "mb-sdk";

const mbListCardRow1 = new PlatformIntegration.MBListCardRow("1", "example title", "example description", 10);
const mbListCardRow2 = new PlatformIntegration.MBListCardRow("2", "example title", "example description", 11);
const listSection1 = new PlatformIntegration.ListSection("Example section", [mbListCardRow1, mbListCardRow2]);
const listPayload = new PlatformIntegration.List({
	messageBoxBody: "Body example",
	messageBoxOptionsButtonText: "Options",
	listHeader: "Example Header",
	listSections: [listSection1],
});

Template Message

Template Message is a feature provided by WhatsApp that enables the sending of pre-defined and structured messages. These messages are created and approved by WhatsApp, allowing businesses to send standardized templates for various purposes such as order confirmations, appointment reminders, and customer support interactions.

Usage

import { PlatformIntegration } from "mb-sdk";
const recipients = [new PlatformIntegration.MBTemplateRecipient("+1234567890"), new PlatformIntegration.MBTemplateRecipient("+9876543210")];

const templateData = {
	languageLocaleCode: "tr",
	name: "Template Name",
	companyId: "y5ad8d93-x4x4-x4x4-x4x4-0001122a8aar",
	companyPriority: 10,
	whatsappAccountId: "908500000000",
	createdBy: "Mindbehind",
	startNow: true,
	whatsappTemplateId: "222333444555666",
	whatsappTemplateName: "emergency_template",
	whatsappTemplateNamespace: "template-namespace",
	recipients: recipients,
};

const template = PlatformIntegration.new MBTemplate(templateData);

AI Module

The AI module utilizes a threshold to find similar texts.

Input AI

The AI input module awaits the user's input. It examines the proximity of the entered input using a predetermined threshold and facilitates its progression towards the specified connection.

Usage

import { PlatformIntegration } from "mb-sdk";

const inputAi = new PlatformIntegration.InputAI({
	threshold: 0.5,
	aiType: "test_id",
	connections: [
		{ id: 7, intent: "bye" },
		{ id: 8, intent: "help" },
	],
	fallback: 210,
	fallbackCount: 0,
	inputParam: "userInputData",
});

Message AI

The AI Message module considers the user's most recent message. By evaluating the proximity of this message using a threshold, it allows the message to advance towards the designated connection.

Usage

import { PlatformIntegration } from "mb-sdk";

const messageAi = new PlatformIntegration.MessageAI({
	threshold: 0.6,
	aiType: "test_id",
	connections: [
		{ id: 7, intent: "bye" },
		{ id: 8, intent: "help" },
	],
	fallback: 210,
	fallbackCount: 0,
});

Please note that the provided descriptions and usage examples are placeholders. They should be replaced with accurate and meaningful descriptions and usage instructions based on the actual implementation and functionality of each module.

License

Licensed under the MIT License.