@phonghq/go-chat 1.0.22 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/assets/icons/IconSetting.vue.d.ts +2 -0
- package/dist/chat/App.vue.d.ts +2 -0
- package/dist/chat/page/home/ChatList.vue.d.ts +1 -1
- package/dist/chat/page/home/ChatMessageItem.vue.d.ts +11 -0
- package/dist/chat/page/home/Home.vue.d.ts +3 -0
- package/dist/components/chat/call/Calling.vue.d.ts +2 -0
- package/dist/components/chat/common/switch/SwitchBase.vue.d.ts +14 -0
- package/dist/components/chat/common/tab/TabBase.vue.d.ts +30 -0
- package/dist/composable/useListConversations.d.ts +46 -0
- package/dist/constant/color.d.ts +2 -2
- package/dist/go-chat.es.js +28483 -28311
- package/dist/go-chat.umd.js +13 -13
- package/dist/style.css +1 -1
- package/dist/test/assets/icons/IconSetting.vue.js +33 -0
- package/dist/test/chat/App.vue.js +105 -77
- package/dist/test/chat/page/home/ChatList.vue.js +226 -124
- package/dist/test/chat/page/home/ChatMessage.vue.js +19 -164
- package/dist/test/chat/page/home/ChatMessageItem.vue.js +321 -0
- package/dist/test/chat/page/home/Home.vue.js +14 -8
- package/dist/test/chat/page/home/HomeHeader.vue.js +18 -12
- package/dist/test/chat/page/home/InputChat.vue.js +62 -33
- package/dist/test/components/chat/call/Calling.vue.js +19 -22
- package/dist/test/components/chat/common/switch/SwitchBase.vue.js +70 -0
- package/dist/test/components/chat/common/tab/TabBase.vue.js +85 -0
- package/dist/test/components/chat/select/SelectBase.vue.js +15 -17
- package/dist/test/composable/useInitData.js +7 -4
- package/dist/test/composable/useListConversations.js +122 -0
- package/dist/test/composable/usePlivo.js +9 -3
- package/dist/test/constant/color.js +4 -2
- package/dist/test/types/chat/call.js +2 -1
- package/dist/test/utils/chat/auth.js +14 -0
- package/dist/test/utils/chat/phone-string.js +1 -1
- package/dist/types/chat/auth.d.ts +2 -0
- package/dist/types/chat/call.d.ts +1 -0
- package/dist/types/chat/global.d.ts +2 -1
- package/dist/types/conversation.d.ts +1 -0
- package/dist/types/message.d.ts +5 -0
- package/dist/utils/chat/auth.d.ts +5 -0
- package/dist/utils/chat/phone-string.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
|
2
|
+
import { TOPIC_HOME, TOPIC_STATUS_USER } from '../constant/mqtt';
|
|
3
|
+
import { addHandleMqttMessage, connectMqtt, removeHandleMqttMessage, subscribeToTopic, unsubscribeFromTopic } from '../plugins/mqtt';
|
|
4
|
+
import { dataProfile } from '../utils/chat/auth';
|
|
5
|
+
import { useDebounce } from '../utils/debounce';
|
|
6
|
+
import { getConversation } from '../utils/chat/conversation';
|
|
7
|
+
import { readMessages } from '../utils/chat/message';
|
|
8
|
+
import { useDigibot } from '../composable/useDigibot';
|
|
9
|
+
const { digibotData, digibotId } = useDigibot();
|
|
10
|
+
export const useListConversations = (is_unknown) => {
|
|
11
|
+
let pageCount = 0;
|
|
12
|
+
const listConversations = ref([]);
|
|
13
|
+
const params = ref({
|
|
14
|
+
page: 1,
|
|
15
|
+
search: ''
|
|
16
|
+
});
|
|
17
|
+
const isLoadingSearch = ref(false);
|
|
18
|
+
onMounted(() => {
|
|
19
|
+
handleConnectMqtt();
|
|
20
|
+
});
|
|
21
|
+
onUnmounted(() => {
|
|
22
|
+
handleDisconnectMqtt;
|
|
23
|
+
});
|
|
24
|
+
const handleDisconnectMqtt = () => {
|
|
25
|
+
TOPIC_HOME.forEach((item) => {
|
|
26
|
+
unsubscribeFromTopic(item + dataProfile.value?.id);
|
|
27
|
+
removeHandleMqttMessage('chat-list-' + item);
|
|
28
|
+
});
|
|
29
|
+
if (dataProfile.value?.user_type == 'tenant') {
|
|
30
|
+
subscribeToTopic(TOPIC_STATUS_USER + dataProfile.value?.id);
|
|
31
|
+
removeHandleMqttMessage('chat-list-' + TOPIC_STATUS_USER);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const handleConnectMqtt = async () => {
|
|
35
|
+
try {
|
|
36
|
+
if (dataProfile.value) {
|
|
37
|
+
await connectMqtt();
|
|
38
|
+
TOPIC_HOME.forEach((item) => {
|
|
39
|
+
subscribeToTopic(item + dataProfile.value?.id);
|
|
40
|
+
addHandleMqttMessage('chat-list-' + item, item + dataProfile.value?.id, mqttMessageHandler);
|
|
41
|
+
});
|
|
42
|
+
subscribeToTopic(TOPIC_STATUS_USER + dataProfile.value?.id);
|
|
43
|
+
addHandleMqttMessage('chat-list-' + TOPIC_STATUS_USER, TOPIC_STATUS_USER + dataProfile.value?.id, mqttMessageHandler);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error(error);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const mqttMessageHandler = (topic, data) => {
|
|
51
|
+
getDataMqtt();
|
|
52
|
+
if (topic === TOPIC_HOME[0] + dataProfile.value?.id) {
|
|
53
|
+
const index = listConversations.value.findIndex((item) => item.id === data.id);
|
|
54
|
+
const hasChatBox = listConversations.value.findIndex((item) => item.id === digibotId);
|
|
55
|
+
if (index != -1) {
|
|
56
|
+
listConversations.value.splice(index, 1);
|
|
57
|
+
}
|
|
58
|
+
if (hasChatBox > -1) {
|
|
59
|
+
listConversations.value.splice(1, 0, data);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
listConversations.value.unshift(data);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (topic === TOPIC_HOME[1] + dataProfile.value?.id) {
|
|
66
|
+
const index = listConversations.value.findIndex((item) => item.id === data.id);
|
|
67
|
+
if (index != -1) {
|
|
68
|
+
listConversations.value[index].unread_count = 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (topic === TOPIC_HOME[2] + dataProfile.value?.id) {
|
|
72
|
+
listConversations.value.unshift(data?.conversations);
|
|
73
|
+
}
|
|
74
|
+
if (topic === TOPIC_STATUS_USER + dataProfile.value?.id) {
|
|
75
|
+
const index = listConversations.value.findIndex((e) => e.receiver_id == Number(data?.customer_id));
|
|
76
|
+
if (index != -1) {
|
|
77
|
+
listConversations.value[index].status = data.is_online ? 1 : 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const getDataMqtt = useDebounce(() => {
|
|
82
|
+
getData(undefined, { hideLoading: true, reset: true });
|
|
83
|
+
}, 5000);
|
|
84
|
+
const getData = async (data, option) => {
|
|
85
|
+
try {
|
|
86
|
+
// if (!option?.hideLoading) isLoadingSearch.value = true
|
|
87
|
+
params.value = { ...params.value, ...(data ?? {}) };
|
|
88
|
+
const res = await getConversation({ ...params.value, is_unknown });
|
|
89
|
+
if (option?.reset) {
|
|
90
|
+
listConversations.value = [];
|
|
91
|
+
if (is_unknown == 0)
|
|
92
|
+
listConversations.value.push(digibotData);
|
|
93
|
+
await nextTick();
|
|
94
|
+
}
|
|
95
|
+
listConversations.value.push(...(res?.items ?? []));
|
|
96
|
+
params.value.page = res?._meta?.currentPage || 1;
|
|
97
|
+
pageCount = res?._meta?.pageCount || 1;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
console.error(error);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
// isLoadingSearch.value = false
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const handleReadMessage = (receiver_id) => {
|
|
107
|
+
const index = listConversations.value.findIndex((e) => e.receiver_id == receiver_id);
|
|
108
|
+
if (index > -1) {
|
|
109
|
+
if (listConversations.value[index].unread_count) {
|
|
110
|
+
readMessages(listConversations.value[index].id);
|
|
111
|
+
listConversations.value[index].unread_count = 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
listConversations,
|
|
117
|
+
params,
|
|
118
|
+
pageCount,
|
|
119
|
+
getData,
|
|
120
|
+
handleReadMessage
|
|
121
|
+
};
|
|
122
|
+
};
|
|
@@ -25,6 +25,9 @@ export function usePlivo(callback) {
|
|
|
25
25
|
plivoBrowserSdk.client.on('onCallFailed', (data, callInfo) => {
|
|
26
26
|
handleCallFailed(data, callInfo);
|
|
27
27
|
});
|
|
28
|
+
plivoBrowserSdk.client.on('onIncomingCallCanceled', (callInfo) => {
|
|
29
|
+
handleIncomingCallCanceled(callInfo);
|
|
30
|
+
});
|
|
28
31
|
plivoBrowserSdk.client.on('onCalling', (data) => console.log('onCallFailed', data));
|
|
29
32
|
plivoBrowserSdk?.client?.on?.('onIncomingCall', (callerID, extraHeaders, callInfo) => {
|
|
30
33
|
handleIncomingCall(callInfo);
|
|
@@ -34,9 +37,8 @@ export function usePlivo(callback) {
|
|
|
34
37
|
// plivoBrowserSdk?.client?.on?.('onLoginFailed', () => console.log('Login failed'))
|
|
35
38
|
// plivoBrowserSdk?.client?.on?.('remoteAudioStatus', () => console.log('remoteAudioStatus'))
|
|
36
39
|
await plivoBrowserSdk?.client?.login('webcall003079673454891827', '123456abcA!');
|
|
37
|
-
const speaker = document.getElementById(
|
|
38
|
-
if (speaker)
|
|
39
|
-
plivoBrowserSdk?.client?.setAudioElement(speaker);
|
|
40
|
+
// const speaker = document.getElementById('go-chat-remote-audio')
|
|
41
|
+
// if (speaker) plivoBrowserSdk?.client?.setAudioElement(speaker)
|
|
40
42
|
console.log('Registered with token');
|
|
41
43
|
}
|
|
42
44
|
catch (err) {
|
|
@@ -63,6 +65,7 @@ export function usePlivo(callback) {
|
|
|
63
65
|
}
|
|
64
66
|
};
|
|
65
67
|
const handleCallTerminated = (data, callInfo) => {
|
|
68
|
+
console.log(data, callInfo);
|
|
66
69
|
if (CallUuid === callInfo.callUUID) {
|
|
67
70
|
callback(PLIVO_CALL_STATUS.CALL_END, { message: data?.reason });
|
|
68
71
|
CallUuid = '';
|
|
@@ -127,6 +130,9 @@ export function usePlivo(callback) {
|
|
|
127
130
|
custom_reject?.(data);
|
|
128
131
|
callback(PLIVO_CALL_STATUS.CALL_END, { message: data });
|
|
129
132
|
};
|
|
133
|
+
const handleIncomingCallCanceled = (callInfo) => {
|
|
134
|
+
callback(PLIVO_CALL_STATUS.CALL_END, { reason: callInfo.reason ?? '' });
|
|
135
|
+
};
|
|
130
136
|
return {
|
|
131
137
|
plivoLogin,
|
|
132
138
|
plivoCallAnswer,
|
|
@@ -8,9 +8,11 @@ var Color;
|
|
|
8
8
|
Color["Primary"] = "#0051E6";
|
|
9
9
|
Color["Primary_Hover"] = "#699FF5";
|
|
10
10
|
Color["Primary_RGB"] = "41, 121, 255";
|
|
11
|
-
|
|
11
|
+
// Error = '#ff3b3b',
|
|
12
|
+
Color["Error"] = "#EF4444";
|
|
12
13
|
Color["Error_Hover"] = "#FF8A75";
|
|
13
|
-
|
|
14
|
+
// Success = '#1DA91D',
|
|
15
|
+
Color["Success"] = "#22C55E";
|
|
14
16
|
Color["Success_Hover"] = "#5FD9A0";
|
|
15
17
|
Color["Success_Bg"] = "#E9FFE4";
|
|
16
18
|
Color["Warning"] = "#f3a22c";
|
|
@@ -33,6 +33,19 @@ export const getProfile = async () => {
|
|
|
33
33
|
const res = await axios.get('/api/v1/message/user/me');
|
|
34
34
|
localStorage.setItem('chat_user', JSON.stringify(res));
|
|
35
35
|
dataProfile.value = res;
|
|
36
|
+
// dataProfile.value = Object.fromEntries(
|
|
37
|
+
// Object.entries(res).filter(([key]) => !['tenant_phone'].includes(key))
|
|
38
|
+
// ) as IResProfile
|
|
39
|
+
return res;
|
|
40
|
+
};
|
|
41
|
+
export const checkTenantPhone = async () => {
|
|
42
|
+
const id = localStorage.getItem('chat_id');
|
|
43
|
+
const res = await axios.get(`/api/v1/message/tenant/get-info?tenant_name=${id}`);
|
|
44
|
+
console.log(res);
|
|
45
|
+
if (dataProfile.value)
|
|
46
|
+
dataProfile.value.tenant_phone = res?.go_chat_phone ?? '';
|
|
47
|
+
if (dataProfile.value)
|
|
48
|
+
dataProfile.value.tenant_phone_limit = Number(res?.go_chat_phone_limit ?? 0);
|
|
36
49
|
return res;
|
|
37
50
|
};
|
|
38
51
|
export const submitTenantPhone = async (body) => {
|
|
@@ -48,6 +61,7 @@ export const logout = async () => {
|
|
|
48
61
|
localStorage.removeItem('chat_domain');
|
|
49
62
|
localStorage.removeItem('chat_id');
|
|
50
63
|
try {
|
|
64
|
+
gapMiniAppSdk?.getInstance()?.closeApp?.();
|
|
51
65
|
if (gapMiniAppSdk?.getInstance()?.getBridge()) {
|
|
52
66
|
gapMiniAppSdk?.getInstance()?.closeApp();
|
|
53
67
|
}
|
|
@@ -10,5 +10,6 @@ export declare const PLIVO_CALL_STATUS: {
|
|
|
10
10
|
readonly CALL_START: "in-progress";
|
|
11
11
|
readonly CALL_END: "completed";
|
|
12
12
|
readonly NO_ANSWER: "no-answer";
|
|
13
|
+
readonly CANCEL: "cancel";
|
|
13
14
|
};
|
|
14
15
|
export type PlivoCallStatusType = (typeof PLIVO_CALL_STATUS)[keyof typeof PLIVO_CALL_STATUS];
|
|
@@ -12,6 +12,7 @@ export interface GoChatInstance {
|
|
|
12
12
|
unreadCount: number;
|
|
13
13
|
getUserRemote: () => (IResUser | null);
|
|
14
14
|
callStatus: PlivoCallStatusType | null;
|
|
15
|
+
callLabel: string;
|
|
15
16
|
startCall: (() => Promise<void>) | undefined;
|
|
16
17
|
endCall: (() => void) | undefined;
|
|
17
18
|
}
|
|
@@ -21,6 +22,6 @@ export interface CallInstance {
|
|
|
21
22
|
startCall: ((data: IResUser) => Promise<void>);
|
|
22
23
|
endCall: (() => void);
|
|
23
24
|
answer: (() => Promise<void>);
|
|
24
|
-
label: ComputedRef<
|
|
25
|
+
label: ComputedRef<string>;
|
|
25
26
|
}
|
|
26
27
|
export type PAGE_RESPONSE = 'mobile' | 'tablet';
|
package/dist/types/message.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export type IResMessage = {
|
|
|
16
16
|
sender_id: number;
|
|
17
17
|
receiver_id: number;
|
|
18
18
|
message: string | null;
|
|
19
|
+
message_uuid?: string | null;
|
|
20
|
+
is_call?: number | null;
|
|
21
|
+
duration?: number | null;
|
|
22
|
+
record_url?: string | null;
|
|
23
|
+
call_status?: string | null;
|
|
19
24
|
created_at: string;
|
|
20
25
|
attachments: IAttachment[];
|
|
21
26
|
state?: MessageStateType;
|
|
@@ -14,6 +14,8 @@ export declare const dataProfile: import("vue").Ref<{
|
|
|
14
14
|
username: string;
|
|
15
15
|
tenant_id: string | null;
|
|
16
16
|
phone: string;
|
|
17
|
+
tenant_phone: string;
|
|
18
|
+
tenant_phone_limit: number;
|
|
17
19
|
avatar: string | null;
|
|
18
20
|
user_type: "customer" | "tenant";
|
|
19
21
|
color: string;
|
|
@@ -22,6 +24,8 @@ export declare const dataProfile: import("vue").Ref<{
|
|
|
22
24
|
username: string;
|
|
23
25
|
tenant_id: string | null;
|
|
24
26
|
phone: string;
|
|
27
|
+
tenant_phone: string;
|
|
28
|
+
tenant_phone_limit: number;
|
|
25
29
|
avatar: string | null;
|
|
26
30
|
user_type: "customer" | "tenant";
|
|
27
31
|
color: string;
|
|
@@ -41,6 +45,7 @@ export declare const setDataLogin: (id: string, token: string, domain: string) =
|
|
|
41
45
|
export declare const loginTenant: (body: IBodyLoginTenant) => Promise<any>;
|
|
42
46
|
export declare const loginLink: (params: IPramsLoginLink) => Promise<any>;
|
|
43
47
|
export declare const getProfile: () => Promise<IResProfile>;
|
|
48
|
+
export declare const checkTenantPhone: () => Promise<any>;
|
|
44
49
|
export declare const submitTenantPhone: (body: {
|
|
45
50
|
phone: string;
|
|
46
51
|
tenant_id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const formatPhone10number: (phone: string, dial
|
|
1
|
+
export declare const formatPhone10number: (phone: string, dial?: string) => string;
|