Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

vuejs chatbot widget

<template>    <div id="app">      <Chat        iconColorProp="#e6e6e6"        messageOutColorProp="#4d9e93"        messageInColorProp="#f1f0f0"        messageBackgroundColorProp="#ffffff"        :messageListProp="messageList"        :initOpenProp="initOpen"        @onToggleOpen="handleToggleOpen"        @onMessageWasSent="handleMessageReceived"      />    </div></template> <script>import {Chat} from 'vue-chat-widget'import incomingMessageSound from '../assets/notification.mp3' // pick an audio file for chat response export default {  name: "app",  components: {    Chat,  },  data: () => {    return {      messageList: [],      initOpen: false,      toggledOpen: false    }  },  methods: {    // Send message from you    handleMessageReceived(message) {      this.messageList.push(message)    },    // Receive message from them (handled by you with your backend)    handleMessageResponse(message) {       if (message.length > 0) {            this.messageList.push({ body: message, author: 'them' })        }    },    // Chat toggled open event emitted    handleToggleOpen(open) {      this.toggledOpen = open      // connect/disconnect websocket or something    },    // Audible chat response noise, use whatever noise you want    handleMessageResponseSound() {      const audio = new Audio(incomingMessageSound)      audio.addEventListener('loadeddata', () => {        audio.play()      })    },  },  // init chat with a message  mounted() {    this.messageList.push({ body: 'Welcome to the chat, I'm David!', author: 'them' })  },  watch: {    messageList: function(newList) {      const nextMessage = newList[newList.length - 1]      const isIncoming = (nextMessage || {}).author !== 'you'      if (isIncoming && this.toggledOpen) {        this.handleMessageResponseSound()      }    }  }}</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: js arrays in arrays 
Javascript :: short-circuit evaluation javascript 
Javascript :: useeffect cleanup function 
Javascript :: http_proxy 
Javascript :: remove second last element from array javascript 
Javascript :: how to return when child process is complete in node js 
Javascript :: socket io websocket connection 
Javascript :: tinymce for react 
Javascript :: aws lambda function setup for node js 
Javascript :: express rate limit 
Javascript :: bot react message with custom emoji 
Javascript :: adding cors in angular 
Javascript :: Search by text score in mongodb 
Javascript :: how to make a quiz in javascript 
Javascript :: javascript call 
Javascript :: (this).find 
Javascript :: how to remove first element of array in javascript 
Javascript :: random chars javascript 
Javascript :: !! javascript 
Javascript :: what is observable in angular 
Javascript :: express framework 
Javascript :: what is a blob in javascript 
Javascript :: javascript Prevent Object MutationPassed 
Javascript :: untrusted health sourcesa 
Javascript :: AND Or condition in text with bracket how to divide in javascript 
Javascript :: capacitorjs get zip code example 
Javascript :: how to remove document.getElementById("myDropdown").classList.toggle("show"); 
Javascript :: dynamic thumbnail on hover in javascript 
Javascript :: servers for node js 
Javascript :: node alternative to btoa 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =