|
|
@ -1,15 +1,15 @@
|
|
|
|
import { create } from "zustand";
|
|
|
|
import { create } from "zustand";
|
|
|
|
import { VonageClient } from "@vonage/client-sdk";
|
|
|
|
import { VonageClient, LoggingLevel } from "@vonage/client-sdk";
|
|
|
|
import { fetchJSON } from "@/utils/request";
|
|
|
|
import { fetchJSON } from "@/utils/request";
|
|
|
|
import { prepareUrl, isNotEmpty } from "@/utils/commons";
|
|
|
|
import { prepareUrl, isNotEmpty, } from "@/utils/commons";
|
|
|
|
import { VONAGE_URL, DATETIME_FORMAT } from "@/config";
|
|
|
|
import { VONAGE_URL, DATETIME_FORMAT } from "@/config";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
|
|
|
|
|
|
|
const callCenterStore = create((set, get) => ({
|
|
|
|
const callCenterStore = create((set, get) => ({
|
|
|
|
client: new VonageClient({
|
|
|
|
client: new VonageClient({
|
|
|
|
// region: "AP",
|
|
|
|
region: "AP",
|
|
|
|
// apiUrl: "https://api-ap-3.vonage.com", websocketUrl: "wss://ws-ap-3.vonage.com",
|
|
|
|
// apiUrl: "https://api-ap-3.vonage.com", websocketUrl: "wss://ws-ap-3.vonage.com",
|
|
|
|
loggingLevel: 'Verbose',
|
|
|
|
loggingLevel: LoggingLevel.Debug,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
call_id: 0,
|
|
|
|
call_id: 0,
|
|
|
|
loading: false,
|
|
|
|
loading: false,
|
|
|
@ -35,6 +35,10 @@ const callCenterStore = create((set, get) => ({
|
|
|
|
.catch(error => {
|
|
|
|
.catch(error => {
|
|
|
|
log("Error creating session: ", error);
|
|
|
|
log("Error creating session: ", error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
client
|
|
|
|
|
|
|
|
.getUser('me')
|
|
|
|
|
|
|
|
.then((user) => log('getUser --me', user))
|
|
|
|
|
|
|
|
.catch((error) => log);
|
|
|
|
|
|
|
|
|
|
|
|
client.on("sessionError", reason => {
|
|
|
|
client.on("sessionError", reason => {
|
|
|
|
// After creating a session
|
|
|
|
// After creating a session
|
|
|
@ -82,7 +86,8 @@ const callCenterStore = create((set, get) => ({
|
|
|
|
if (client) {
|
|
|
|
if (client) {
|
|
|
|
set({ loading: true });
|
|
|
|
set({ loading: true });
|
|
|
|
client
|
|
|
|
client
|
|
|
|
.serverCall({ to: phone_number })
|
|
|
|
// .serverCall({ to: phone_number, callee: phone_number, device_name: 'SalesCRM' })
|
|
|
|
|
|
|
|
.serverCall({ to: phone_number, })
|
|
|
|
.then(callId => {
|
|
|
|
.then(callId => {
|
|
|
|
log("Id of created call: ", callId);
|
|
|
|
log("Id of created call: ", callId);
|
|
|
|
set({ call_id: callId });
|
|
|
|
set({ call_id: callId });
|
|
|
|