4.3.7 • Published 3 months ago

vue-converse v4.3.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

vue-converse

Build a form using a chat interface.

Install

npm install vue-converse

// or
yarn add vue-converse

Usage

Import VueConverse as a component where you want to use it.

import VueConverse from 'vue-converse'

Use it on your app by passing the required props:

<VueConverse
  :dialog="messages"
  @skip="getNextBotMessage"
  @response="handleResponse"
/>

Handling the response

data () {
  return {
    questionnaire: {}, // keep responses
    messages: [
      {
        type: 'text',
        text: 'How are you doing?',
        action: {
          type: 'buttons',
          field: 'fellings',
          options: [
            {
              label: 'Great',
              value: false,
              style: 'btn btn-green',
            },
            {
              label: 'Not so good',
              value: true,
            },
          ],
        },
      },
    ],
    dialog: [],
    currentDialog: 0,
  }
},

methods: {
  handleResponse({ field, response }) {
    this.questionnaire[field] = response // update your response data

    this.dialog.push({ // append messages to chat
      agent: 'user',
      type: 'text',
      text: response,
    })

    this.getNextBotMessage() // ask something else
  },

  getNextBotMessage() {
    this.currentDialog += 1
    const nextMessage = this.messages[this.currentDialog]
    this.dialog.push(nextMessage)
  }
}

Message structure:

FieldDescription
Agent RequiredIndicates if the message comes from the bot or the user.
Type RequiredIndicates the type of the message. For now, the only supported type is text
Message RequiredString that indicates the message that will be shown to the user.
RequiredIf the message is set to required, the "skip question" option won't be available. Default Value: false
FinishIndicates if the conversation should finish after this question. Default Value: false
DelayIf set up, the typing component is shown with this duration.
Actionlink
Conditional Message......

Action

The action is optional and represents what the user can do after the bot's message. The supported action types are: input, buttons and dropdown.

If the action type is buttons or dropdown, you should set up a required field options, that contains an array of the options that will be displayed to the user.

FieldDescription
Type RequiredAccept types: input, buttons and dropdown
Field RequiredString that is used to represent an unique user response
OptionsThis represents the options to be displayed. Required for button and dropdown

Example:

const messages = [
  {
    agent: 'bot',
    type: 'text',
    text: 'Hi, what\'s your name'
    delay: 2000,
    finish: false
    conditionalMessage: {}
    action: {
      required: true
      type: 'buttons',
      field: 'name',
      options: [
        {
          label: 'I don\'t know', // Button/Select label
          value: 'NOT_SURE', // Button/Select value
        },
      ],
    }
  },
  ...
]

Props

Available props's component:

NameTypeDefaultDescription
dialogMessages[]Required. Data of Messages
labelsLabelsDEFAULT_LABELSLabels for the "skip" and "send" buttons
optionsOptionsDEFAULT_OPTIONSAllow to enable and disable features

Events

Available event's component:

NameDescriptionData
responseHandles the user response to a message (action){ field: 'isHappy', value: true, text: 'Yes' }
skipGo to the next message after the user has skipped an actionnone
registerDateTimeFor every message, this event handles the DateTime it was sentFri Jul 15 2022 10:58:11 GMT-0300 (Brasilia Standard Time)

Features

DateTime

VueConverse is able to display the time when the message was sent in chat and/or pass the DateTime to a registerDateTime event.

Both options are disabled by default and can be enabled by passing the option object to VueConverse as props, like so:

<VueConverse
  ...
  :options="{ displayDateTime: true, registerDateTime: true }"
  @registerDateTime="registerDateTime"
/>

Remember to always pass the registerDateTime event in case you want to have access to this data.

4.3.7

3 months ago

4.3.6

3 months ago

4.3.5

6 months ago

3.3.2

6 months ago

4.3.2

6 months ago

4.3.4

6 months ago

4.3.3

6 months ago

3.2.2

8 months ago

3.0.4

12 months ago

3.2.1

10 months ago

3.2.0

11 months ago

3.1.0

11 months ago

3.0.5

11 months ago

1.2.0

1 year ago

3.0.3

12 months ago

3.0.2

1 year ago

3.0.1

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.3.0

2 years ago

0.1.2

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.1.3

2 years ago

0.1.0

2 years ago

1.0.0

2 years ago