Coder Social home page Coder Social logo

alexedtionweb / blip-chat-widget Goto Github PK

View Code? Open in Web Editor NEW

This project forked from takenet/blip-chat-widget

0.0 1.0 0.0 589 KB

Widget to enable add the BLiP Chat in your web app or site

Home Page: https://blip.ai

License: MIT License

HTML 26.87% JavaScript 66.37% CSS 6.76%

blip-chat-widget's Introduction

Running

  • npm install
  • npm start
  • Project will be running on http://localhost:3000

Installation

Add the script element inside the body of your web page. To get the script with your app key, go to BLiP portal. Choose the desired bot, go to the upper menu and access Channels > Blip Chat. On the Setup tab you will be able to get the required script. You also have to sign up all website domains into which Blip Chat will be included, otherwise it will not work. That's all :)

For publishing purposes, download the script and make a reference to it locally. CDN may have availability problems and cause BLiP Chat instability.

<script src="https://unpkg.com/[email protected].*" type="text/javascript"></script>
<script>
    (function () {
        window.onload = function () {
            new BlipChat()
            .withAppKey('YOUR-APP-KEY')
            .withButton({"color":"#2CC3D6"})
            .build();
        }
    })();
</script>

You can also use BlipChat Widget as npm module:

import { BlipChat } from "blip-chat-widget";
new BlipChat()
  .withAppKey("YOUR-APP-KEY")
  .withButton({ color: "#2CC3D5" })
  .build();

Optional parameters

Property Description
withAppKey Set the bot's app key
withButton Set the button's color and icon
withAuth Set the auth type, user identity and password (see more)
withAccount Set the user account (see more)
withEventHandler Set the events to be called. Params: name and function*
withTarget Set the element that will contain the chat
withCustomStyle Set a custom style for BLiP Chat

*Guest auth will keep the same generated 'userIdentity' for 30 days. When using DEV auth type, 'userIdentity' and 'userPassword' are required.

*Supported events:

  • OnEnter - Set the event to run on opening the chat
  • OnLeave - Set the event to run on closing the chat
  • OnLoad - Set the event to run on finish loading the chat
  • OnCreateAccount - Set the event to run on creating new user account

Click here to see how to use BLiP Chat in a logged web page.

Example 1

Connecting on BLiP Chat passing user auth, account and event handlers.

<script src="https://unpkg.com/[email protected].*" type="text/javascript">
</script>
<script>
    (function () {
        window.onload = function () {
          var builder = new BlipChat()
            .withAppKey('YmxpcHRlc3RjYXJkczoxOGE5NzUwYS1kZjAxLTRhNTgtODA1ZC1kY2ExYmI2NTBmZjk=')
            .withButton({
              color: '#F00',
              icon:
                'https://www.google.com.br/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
            })
            .withAuth({
              authType: BlipChat.DEV_AUTH,
              userIdentity: '1234567',
              userPassword: 'MTIzNDU2',
            })
            .withAccount({
              fullName: 'John Doe',
              email:'[email protected]',
              phoneNumber: '+15055034455',
              city: 'Decatur',
            })
            .withEventHandler(BlipChat.ENTER_EVENT, function () {
              console.log('enter')
            })
            .withEventHandler(BlipChat.LEAVE_EVENT, function () {
              console.log('leave')
            })
            .withEventHandler(BlipChat.LOAD_EVENT, function () {
              console.log('chat loaded')
            })
            .withEventHandler(BlipChat.CREATE_ACCOUNT_EVENT, function () {
              console.log('account created')
            })
          builder.build()
      }
    })();
</script>

Example 2

Connect on BLiP Chat and set create account event to send chat state on the first time that the user is interacting with the bot.

<script src="https://unpkg.com/[email protected].*" type="text/javascript"></script>
<script>
    (function () {
        window.onload = function () {
          var blipClient = new BlipChat()
          .withAppKey('YOUR-APP-KEY')
          .withEventHandler(BlipChat.CREATE_ACCOUNT_EVENT, function () {
              blipClient.sendMessage({
                  "type": "text/plain",
                  "content": "Start"
              });
          });
          blipClient.build();
        }
    })();
</script>

Example 3

Connect on BLiP Chat and use a custom style.

<script src="https://unpkg.com/[email protected].*" type="text/javascript"></script>
<script>
    (function () {
        window.onload = function () {

          var customStyle = `#message-input {
              box-sizing: border-box;
              border: 1px solid #0CC8CC;
              border-radius: 6px;
              background: #252B39;
            }
            #message-input textarea {
              background: #252B39;
              font-size: 12px;
              color: white;
            }`

          var blipClient = new BlipChat()
          .withAppKey('YOUR-APP-KEY')
          .withCustomStyle(customStyle);
          blipClient.build();
        }
    })();
</script>

Guidelines

HTTPS

It's pretty recommended to use SSL certificate for the site that will receive the BLiP Chat. This is necessary for security reasons and for some cards to work properly.

Permissions

BLiP Chat needs the document.referrer value to communicate with the website hosting it. But in some servers, we can have a Referrer-Policy header configurated. In this case, we cannot have a no-referrer and same-origin policies, because we won't receive the value in this situation (we just receive a blank string).

Reference Article: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy


If your website blocks iframe origins by using the Content-Security-Policy, you need to add the domain https://chat.blip.ai/ on frame-src policy. If you do not add that domain, the BLiP Chat will not load and the following error will be showed on browser console:

Refused to frame 'https://chat.blip.ai/' because it violates the following Content Security Policy directive: "frame-src {domains}"

If you are using IIS server, your web.config file will looks like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="true" />
        <httpProtocol>
                <customHeaders>
                    <add name="Content-Security-Policy" value="frame-src 'self' https://chat.blip.ai/;" />
                </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>

Reference Article: https://developers.google.com/web/fundamentals/security/csp

Geolocalization Card

This card only works if your website has a SSL certificate and is accessed via HTTPS. This occurs because of security polices of browsers.

Script usage

Features

Destroy chat widget

Destroys the widget that was added to your page.

blipClient.destroy();

Toogle chat widget

Toggles the chat widget window.

blipClient.toogleChat();

Send message

Sends a message to your bot. The message can be a simple text or any LIME Protocol document. See example below:

<script src="https://unpkg.com/[email protected].*" type="text/javascript"></script>
<script>
(function () {
        window.onload = function () {
			var blipClient = new BlipChat();
			blipClient.withAppKey('YOUR-APP-KEY')
		.withEventHandler(BlipChat.LOAD_EVENT, function () {
      blipClient.sendMessage({
                "type": "text/plain",
                "content": "This is my first message"
        });
			})
            .build();
        }
    })();
</script>

Send command

Sends a command. See example below:

<script src="https://unpkg.com/[email protected].*" type="text/javascript"></script>
<script>
(function () {
        window.onload = function () {
			var blipClient = new BlipChat();
			blipClient.withAppKey('YOUR-APP-KEY')
		.withEventHandler(BlipChat.LOAD_EVENT, function () {
      blipClient.sendCommand({
        id: "ag0asd0as-daasdasd0a",
        to: '[email protected]',
        method: Lime.CommandMethod.GET,
        uri: '/entities'
      })
      .build();
        }
    })();
</script>

blip-chat-widget's People

Contributors

arthursoas avatar brunoalis avatar brunocamarda avatar luizguicl avatar nbontempo avatar ravpacheco avatar samwx avatar victorbalbo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.