mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
refactor: remove widget token
This commit is contained in:
@@ -7,11 +7,9 @@ COPY package*.json ./
|
||||
# Set the environment variables
|
||||
ARG REACT_APP_WIDGET_API_URL
|
||||
ARG REACT_APP_WIDGET_CHANNEL
|
||||
ARG REACT_APP_WIDGET_TOKEN
|
||||
|
||||
ENV REACT_APP_WIDGET_API_URL=${REACT_APP_WIDGET_API_URL}
|
||||
ENV REACT_APP_WIDGET_CHANNEL=${REACT_APP_WIDGET_CHANNEL}
|
||||
ENV REACT_APP_WIDGET_TOKEN=${REACT_APP_WIDGET_TOKEN}
|
||||
|
||||
# Installer stage: Installs dependencies
|
||||
FROM base AS installer
|
||||
|
||||
@@ -20,7 +20,6 @@ import { useColors } from '../providers/ColorProvider';
|
||||
import { useConfig } from '../providers/ConfigProvider';
|
||||
import { useSettings } from '../providers/SettingsProvider';
|
||||
import { useSocket } from '../providers/SocketProvider';
|
||||
import './UserSubscription.scss';
|
||||
import { useWidget } from '../providers/WidgetProvider';
|
||||
import {
|
||||
Direction,
|
||||
@@ -28,6 +27,7 @@ import {
|
||||
TMessage,
|
||||
TOutgoingMessageType,
|
||||
} from '../types/message.types';
|
||||
import './UserSubscription.scss';
|
||||
|
||||
const UserSubscription: React.FC = () => {
|
||||
const config = useConfig();
|
||||
@@ -55,7 +55,7 @@ const UserSubscription: React.FC = () => {
|
||||
messages: TMessage[];
|
||||
profile: ISubscriber;
|
||||
}>(
|
||||
`/webhook/${config.channel}/?verification_token=${config.token}&first_name=${firstName}&last_name=${lastName}`,
|
||||
`/webhook/${config.channel}/?first_name=${firstName}&last_name=${lastName}`,
|
||||
);
|
||||
const { messages, profile } = body;
|
||||
|
||||
|
||||
@@ -9,6 +9,5 @@
|
||||
export const DEFAULT_CONFIG = {
|
||||
apiUrl: process.env.REACT_APP_WIDGET_API_URL || 'http://localhost:4000',
|
||||
channel: process.env.REACT_APP_WIDGET_CHANNEL || 'console-channel',
|
||||
token: process.env.REACT_APP_WIDGET_TOKEN || 'test',
|
||||
language: 'en',
|
||||
};
|
||||
|
||||
@@ -19,7 +19,6 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
{...{
|
||||
apiUrl: process.env.REACT_APP_WIDGET_API_URL || 'http://localhost:4000',
|
||||
channel: process.env.REACT_APP_WIDGET_CHANNEL || 'web-channel',
|
||||
token: process.env.REACT_APP_WIDGET_TOKEN || 'token123',
|
||||
language: 'en',
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -289,7 +289,7 @@ const ChatProvider: React.FC<{
|
||||
);
|
||||
setMessage('');
|
||||
const sentMessage = await socketCtx.socket.post<TMessage>(
|
||||
`/webhook/${config.channel}/?verification_token=${config.token}`,
|
||||
`/webhook/${config.channel}/`,
|
||||
{
|
||||
data: {
|
||||
...data,
|
||||
@@ -308,7 +308,7 @@ const ChatProvider: React.FC<{
|
||||
messages: TMessage[];
|
||||
profile: ISubscriber;
|
||||
}>(
|
||||
`/webhook/${config.channel}/?verification_token=${config.token}&first_name=${firstName}&last_name=${lastName}`,
|
||||
`/webhook/${config.channel}/?first_name=${firstName}&last_name=${lastName}`,
|
||||
);
|
||||
|
||||
localStorage.setItem('profile', JSON.stringify(body.profile));
|
||||
|
||||
@@ -13,7 +13,6 @@ import { DEFAULT_CONFIG } from '../constants/defaultConfig';
|
||||
// Define the type for your config, including all possible properties
|
||||
export type Config = {
|
||||
apiUrl: string;
|
||||
token: string;
|
||||
channel: string;
|
||||
language: string;
|
||||
};
|
||||
@@ -23,7 +22,6 @@ const ConfigContext = createContext<Config>(DEFAULT_CONFIG);
|
||||
|
||||
export const ConfigProvider: React.FC<{
|
||||
apiUrl?: string;
|
||||
token?: string;
|
||||
channel?: string;
|
||||
language?: string;
|
||||
children: ReactNode;
|
||||
|
||||
@@ -23,7 +23,6 @@ import { useSubscribe } from './SocketProvider';
|
||||
type ChannelSettings = {
|
||||
menu: IMenuNode[];
|
||||
secret: string;
|
||||
verification_token: string;
|
||||
allowed_domains: string;
|
||||
start_button: boolean;
|
||||
input_disabled: boolean;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { io, Socket, ManagerOptions, SocketOptions } from 'socket.io-client';
|
||||
import { io, ManagerOptions, Socket, SocketOptions } from 'socket.io-client';
|
||||
|
||||
import { Config } from '../providers/ConfigProvider';
|
||||
import {
|
||||
@@ -195,14 +195,16 @@ let socketIoClient: SocketIoClient;
|
||||
* @param handlers Event handlers
|
||||
* @returns Socket io client instance
|
||||
*/
|
||||
export const getSocketIoClient = (config: Config, handlers: SocketIoEventHandlers) => {
|
||||
export const getSocketIoClient = (
|
||||
config: Config,
|
||||
handlers: SocketIoEventHandlers,
|
||||
) => {
|
||||
if (!socketIoClient) {
|
||||
socketIoClient = new SocketIoClient(
|
||||
config.apiUrl,
|
||||
{
|
||||
query: {
|
||||
channel: config.channel,
|
||||
verification_token: config.token,
|
||||
},
|
||||
},
|
||||
handlers,
|
||||
|
||||
Reference in New Issue
Block a user