1.2.0-rc6 • Published 5 years ago

@lightbase/lightbot v1.2.0-rc6

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

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

1.2.0-rc6

5 years ago

1.2.0-rc5

5 years ago

1.2.0-rc4

5 years ago

1.2.0-rc3

5 years ago

1.2.0-rc2

5 years ago

1.2.0-rc1

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago