feat: useVoice

This commit is contained in:
Tristan Yang
2023-03-24 23:07:56 +08:00
parent da00f3b797
commit 92411d0468
20 changed files with 331 additions and 132 deletions
+2 -1
View File
@@ -27,7 +27,8 @@ const whiteList = [
"createAdmin",
"getBotRelatedChannels",
"sendMessageByBot",
"replyWithChatGPT"
"replyWithChatGPT",
"getAgoraVoicingList"
];
const baseQuery = fetchBaseQuery({
+31 -2
View File
@@ -17,10 +17,12 @@ import {
LicenseResponse,
RenewLicense,
RenewLicenseResponse,
AgoraTokenResponse
AgoraTokenResponse,
AgoraVoicingListResponse
} from "../../types/server";
import { Channel } from "../../types/channel";
import { ContentTypeKey } from "../../types/message";
import { updateVoiceInfo } from "../slices/voice";
const defaultExpireDuration = 2 * 24 * 60 * 60;
@@ -115,6 +117,31 @@ export const serverApi = createApi({
url: `group/${id}/agora_token`,
})
}),
getAgoraVoicingList: builder.query<AgoraVoicingListResponse, { appid: string, key: string, secret: string }>({
query: ({ appid, key, secret }) => ({
headers: {
Authorization: `Basic ${btoa(`${key}:${secret}`)}`
},
url: `https://api.agora.io/dev/v1/channel/${appid}`,
}),
async onQueryStarted(data, { dispatch, queryFulfilled }) {
try {
const { data: resp } = await queryFulfilled;
const { success } = resp;
if (success && resp.data.channels.length > 0) {
const [channel] = resp.data.channels;
const [id] = channel.channel_name.split(":").slice(-1);
// todo
dispatch(updateVoiceInfo({
id: +id,
context: "channel"
}));
}
} catch {
console.error("get voice list error");
}
}
}),
getSMTPConfig: builder.query<SMTPConfig, void>({
query: () => ({ url: `admin/smtp/config` })
}),
@@ -327,5 +354,7 @@ export const {
useSendMessageByBotMutation,
useUpdateFrontendUrlMutation,
useGetFrontendUrlQuery,
useLazyGetAgoraTokenQuery
useLazyGetAgoraTokenQuery,
useGetAgoraConfigQuery,
useGetAgoraVoicingListQuery
} = serverApi;