Skip to content

Commit d5fdd37

Browse files
author
Matteo Merola
committed
adjusted documentation for new api
1 parent 4f476ff commit d5fdd37

File tree

1 file changed

+57
-15
lines changed

1 file changed

+57
-15
lines changed

README.md

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,92 @@ Vue.use(Chat)
4444
<template>
4545
<div>
4646
<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"
5049
:onMessageWasSent="onMessageWasSent"
5150
:messageList="messageList"
5251
:newMessagesCount="newMessagesCount"
5352
:isOpen="isChatOpen"
5453
:close="closeChat"
5554
:open="openChat"
5655
: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" />
5960
</div>
6061
</template>
6162
```
6263
```javascript
6364
export default {
65+
name: 'app',
6466
data() {
6567
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
7285
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...)
74113
}
75114
},
76115
methods: {
77-
sendMessage (message) {
116+
sendMessage (text) {
78117
if (text.length > 0) {
79118
this.newMessagesCount = this.isChatOpen ? this.newMessagesCount : this.newMessagesCount + 1
80-
this.onMessageWasSent(message)
119+
this.onMessageWasSent({ author: 'support', type: 'text', data: { text } })
81120
}
82121
},
83122
onMessageWasSent (message) {
84-
this.messageList = [...this.messageList, message]
123+
// called when the user sends a message
124+
this.messageList = [ ...this.messageList, message ]
85125
},
86126
openChat () {
127+
// called when the user clicks on the fab button to open the chat
87128
this.isChatOpen = true
88129
this.newMessagesCount = 0
89130
},
90131
closeChat () {
132+
// called when the user clicks on the botton to close the chat
91133
this.isChatOpen = false
92134
}
93135
}

0 commit comments

Comments
 (0)