Coder Social home page Coder Social logo

vue-freshchat's Introduction

vue-freshchat

A reactive wrapper for Freshchat's JavaScript API

Installation

npm install vue-freshchat
import Vue from "vue";
import VueFreshchat from "vue-freshchat";

Vue.use(VueFreshchat, { appToken: "your-freshchat-token", config: { } }); // config object is optional

Usage

vue-freshchat handles the injection of Freshchat's script into your html and wraps calls to the Freshchat API with methods and exposes them through the $freshchat object in your components.

new Vue({
  el: "#main",
  data() {
    return {
      userExternalId: 1,
      userEmail: "[email protected]",
    };
  },
  mounted() {
    this.$freshchat.setExternalId(this.userExternalId);
    this.$freshchat.open();
  },
  watch: {
    userEmail() {
      this.$freshchat.setUserProperties({ email: this.userEmail });
    },
  },
});

Example App

cd example
npm install
npm run dev

API

Parameters

appToken: (Required) Your freshchat auth token
host: (Optional) Add a custom url to fetch the freshchat script from
config: (Optional) Additional configuration for initializing freshchat

Values

$freshchat.ready

Set to true once the Freshchat script has been loaded.

$freshchat.isOpen

Set via the opened/closed events.

Methods

$freshchat.setExternalId(externalId)

Calls freshchat.setExternalId.

$freshchat.setUserProperties(options)

Calls freshchat.setProperties.

$freshchat.open(/*optional*/ payload)

Calls freshchat.open().

$freshchat.close()

Calls freshchat.close().

$freshchat.toggle()

Calls freshchat.open() if the widget is closed and freshchat.close() if the widget is open.

$freshchat.listen(event, function)

Calls freshchat.on(event, function)

$freshchat.hideWidget()

Will hide the widget bubble, and only show it when it's opened, use this property if you want to create your own personalized bubble

$freshchat.showWidget()

Will display the widget bubble if it has already been hidden

License

MIT

Copyright (c) 2020

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.