Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lightbase/lightbot

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lightbase/lightbot

Javascript Client for Lightbot API

  • 1.2.0-rc3
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
4
Weekly downloads
 
Created
Source

Lightbot.js

About

Lightbot.js is a client javascript SDK

It allows the developer to easily communicate with any lightbot agent.

Example

import { LightbotMessenger } from "lightbot";

const lightbotMessenger = new LightbotMessenger({
  hostURL: "http://localhost:9000",
  agentId: "agent-id",
});

lightbotMessenger.toggleMessenger();

lightbotMessenger.sendMessage({
  type: "plain",
  sender: "human",
  label: "Hello, I need some help!",
});

API Reference

PropertyDescriptionType
messagesMessage historyMessage
sendMessageSends a message to the botFunction(message: Message): void
toggleMessengerToggles messenger open stateFunction()
isMessengerOpenCurrent open stateBoolean
onChangeCalled when any primitive property gets updatedFunction(): void
resetAgentResets all in memory and local storage data related to the bot agent. e.g.: messages, agent data, etc.Function(): void

Message Type

PropertyDescriptionValue
senderMessage sender identification"bot" | "human"
typeType of message"plain" | "link" | "jump"

when type: "plain":

PropertyDescriptionType
labelPlain text messagestring

when type: "link":

PropertyDescriptionType
labelRepresentative link labelstring
linklinkstring

when type: "jump":

PropertyDescriptionType
labelRepresentative jump labelstring
jumpslinkArray<{ label: string; event: string; }>

withLightbotMessenger HOC

Lightbot.js provides a React HOC which can be used to provide a communication interface to your React components.

withLightbotMessenger<ComponentProps>(options: { agentId: string; hostURL: string; })(Component)

How to use

React components are exported from lib/lightbot-react.

import {
  LightbotMessage,
  LightbotMessengerDecoratedProps,
  withLightbotMessenger
} from "lightbot/lib/lightbot-react";

type AppProps = LightbotMessengerDecoratedProps & {
  children: any;
}

class AppDisconnected extends Component<AppProps, {}> {
  public render() {
    const { messages, isMessengerOpen, toggleMessenger } = this.props;
    return (
      <>
        {
          isMessengerOpen ? 
          (<ChatWindow
            messages={messages}
            onMessageSend={this.sendMessage}
          />) : 
          null
        }
        <button onClick={toggleMessenger}>
          {isMessengerOpen ? "close" : "open"}
        </button>
      </>
    );
  }

  private sendMessage = (message: string) => {
    this.props.sendMessage({ type: "plain", label: message });
  }
}

export const App = withLightbotMessenger<AppProps>({
  hostURL: "https://localhost:9000",
  agentId: "agent-id"
})(AppDisconnected);

Live Example

Edit ⚡️Lightbot Chat Widget Example

Injected props

withLightbotMessenger injects the same props as the one defined by the Lightbot API except the onChange is implemented in order to update your React components when any update is available.

License

Apache-2.0

FAQs

Package last updated on 08 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc