@@ -44,50 +44,92 @@ Vue.use(Chat)
44
44
<template >
45
45
<div >
46
46
<beautiful-chat
47
- :participants =" [agentProfile]"
48
- :title =" Support Chat"
49
- :titleImageUrl =" https://a.slack-edge.com/66f9/img/avatars-teams/ava_0001-34.png"
47
+ :participants =" participants"
48
+ :titleImageUrl =" titleImageUrl"
50
49
:onMessageWasSent =" onMessageWasSent"
51
50
:messageList =" messageList"
52
51
:newMessagesCount =" newMessagesCount"
53
52
:isOpen =" isChatOpen"
54
53
:close =" closeChat"
55
54
:open =" openChat"
56
55
:showEmoji =" true"
57
- :showFile =" true" />
58
- <a href =" #" @click.prevent =" openChat()" >Open the chat window</a >
56
+ :showFile =" true"
57
+ :showTypingIndicator =" showTypingIndicator"
58
+ :colors =" colors"
59
+ :alwaysScrollToBottom =" alwaysScrollToBottom" />
59
60
</div >
60
61
</template >
61
62
```
62
63
``` javascript
63
64
export default {
65
+ name: ' app' ,
64
66
data () {
65
67
return {
66
- agentProfile: {
67
- id: ' support' ,
68
- name: ' Support Agent' ,
69
- imageUrl: ' https://a.slack-edge.com/66f9/img/avatars-teams/ava_0001-34.png'
70
- },
71
- messageList: [],
68
+ participants: [
69
+ {
70
+ id: ' user1' ,
71
+ name: ' Matteo' ,
72
+ imageUrl: ' https://avatars3.githubusercontent.com/u/1915989?s=230&v=4'
73
+ },
74
+ {
75
+ id: ' user2' ,
76
+ name: ' Support' ,
77
+ imageUrl: ' https://avatars3.githubusercontent.com/u/37018832?s=200&v=4'
78
+ }
79
+ ], // the list of all the participant of the conversation. `name` is the user name, `id` is used to establish the author of a message, `imageUrl` is supposed to be the user avatar.
80
+ titleImageUrl: ' https://a.slack-edge.com/66f9/img/avatars-teams/ava_0001-34.png' ,
81
+ messageList: [
82
+ { type: ' text' , author: ` me` , data: { text: ` Say yes!` } },
83
+ { type: ' text' , author: ` user1` , data: { text: ` No.` } }
84
+ ], // the list of the messages to show, can be paginated and adjusted dynamically
72
85
newMessagesCount: 0 ,
73
- isChatOpen: false
86
+ isChatOpen: false , // to determine whether the chat window should be open or closed
87
+ showTypingIndicator: ' ' , // when set to a value matching the participant.id it shows the typing indicator for the specific user
88
+ colors: {
89
+ header: {
90
+ bg: ' #4e8cff' ,
91
+ text: ' #ffffff'
92
+ },
93
+ launcher: {
94
+ bg: ' #4e8cff'
95
+ },
96
+ messageList: {
97
+ bg: ' #ffffff'
98
+ },
99
+ sentMessage: {
100
+ bg: ' #4e8cff' ,
101
+ text: ' #ffffff'
102
+ },
103
+ receivedMessage: {
104
+ bg: ' #eaeaea' ,
105
+ text: ' #222222'
106
+ },
107
+ userInput: {
108
+ bg: ' #f4f7f9' ,
109
+ text: ' #565867'
110
+ }
111
+ }, // specifies the color scheme for the component
112
+ alwaysScrollToBottom: false // when set to true always scrolls the chat to the bottom when new events are in (new message, user starts typing...)
74
113
}
75
114
},
76
115
methods: {
77
- sendMessage (message ) {
116
+ sendMessage (text ) {
78
117
if (text .length > 0 ) {
79
118
this .newMessagesCount = this .isChatOpen ? this .newMessagesCount : this .newMessagesCount + 1
80
- this .onMessageWasSent (message )
119
+ this .onMessageWasSent ({ author : ' support ' , type : ' text ' , data : { text } } )
81
120
}
82
121
},
83
122
onMessageWasSent (message ) {
84
- this .messageList = [... this .messageList , message]
123
+ // called when the user sends a message
124
+ this .messageList = [ ... this .messageList , message ]
85
125
},
86
126
openChat () {
127
+ // called when the user clicks on the fab button to open the chat
87
128
this .isChatOpen = true
88
129
this .newMessagesCount = 0
89
130
},
90
131
closeChat () {
132
+ // called when the user clicks on the botton to close the chat
91
133
this .isChatOpen = false
92
134
}
93
135
}
0 commit comments