bot session initialization update
parent
482ef013f5
commit
ba4f0cb72c
|
@ -10,13 +10,16 @@ export function dismissBot() {
|
||||||
return { type: types.DISMISS_BOT };
|
return { type: types.DISMISS_BOT };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadBotSession(botName, userKey) {
|
export function loadBotSession(botName, userKey, botType) {
|
||||||
return async function(dispatch, getState) {
|
return async function(dispatch, getState) {
|
||||||
try {
|
try {
|
||||||
dispatch({ type: types.INITIALIZE_BOT_SESSION_STARTED });
|
const state = getState();
|
||||||
const { frontendSession } = getState();
|
const session = state.bot.session[botType];
|
||||||
const externalId = frontendSession.sessionId;
|
if (session && (session.loading || session.loaded)) return;
|
||||||
const clientApplication = frontendSession.applicationCode;
|
|
||||||
|
dispatch({ type: types.INITIALIZE_BOT_SESSION_STARTED, botType });
|
||||||
|
const externalId = state.frontendSession.sessionId;
|
||||||
|
const clientApplication = state.frontendSession.applicationCode;
|
||||||
const data = await dispatch(
|
const data = await dispatch(
|
||||||
sendHttpRequest(
|
sendHttpRequest(
|
||||||
api.getBotSession(botName, externalId, clientApplication, userKey)
|
api.getBotSession(botName, externalId, clientApplication, userKey)
|
||||||
|
@ -24,7 +27,8 @@ export function loadBotSession(botName, userKey) {
|
||||||
);
|
);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: types.INITIALIZE_BOT_SESSION_SUCCESS,
|
type: types.INITIALIZE_BOT_SESSION_SUCCESS,
|
||||||
payload: data
|
payload: data,
|
||||||
|
botType
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -28,7 +28,7 @@ const BotsManager = ({ bot, actions }) => {
|
||||||
setType(bot.type);
|
setType(bot.type);
|
||||||
|
|
||||||
if (bot.type == botType.none) return;
|
if (bot.type == botType.none) return;
|
||||||
actions.loadBotSession(bots.Zirhan, userKey.unknown);
|
actions.loadBotSession(bots.Zirhan, userKey.unknown, bot.type);
|
||||||
}, [bot.type]);
|
}, [bot.type]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export const botType = {
|
export const botType = {
|
||||||
none: Symbol("none"),
|
none: "none",
|
||||||
wizard: Symbol("wizard")
|
wizard: "wizard"
|
||||||
};
|
};
|
||||||
|
|
||||||
export const bots = {
|
export const bots = {
|
||||||
|
|
|
@ -11,12 +11,25 @@ export default function chatbotReducer(state = initialState.bot, action) {
|
||||||
return { ...state, type: botType.none };
|
return { ...state, type: botType.none };
|
||||||
|
|
||||||
case types.INITIALIZE_BOT_SESSION_STARTED:
|
case types.INITIALIZE_BOT_SESSION_STARTED:
|
||||||
return { ...state, session: { loading: true, loaded: false } };
|
return {
|
||||||
|
...state,
|
||||||
|
session: {
|
||||||
|
...state.session,
|
||||||
|
[action.botType]: { loading: true, loaded: false }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
case types.INITIALIZE_BOT_SESSION_SUCCESS:
|
case types.INITIALIZE_BOT_SESSION_SUCCESS:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
session: { loading: false, loaded: true, ...action.payload }
|
session: {
|
||||||
|
...state.session,
|
||||||
|
[action.botType]: {
|
||||||
|
loading: false,
|
||||||
|
loaded: true,
|
||||||
|
...action.payload
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
case types.INITIALIZE_BOT_CHAT_STARTED:
|
case types.INITIALIZE_BOT_CHAT_STARTED:
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default {
|
||||||
},
|
},
|
||||||
bot: {
|
bot: {
|
||||||
type: null,
|
type: null,
|
||||||
session: { loading: false, loaded: false },
|
session: {},
|
||||||
chat: { loading: false, loaded: false }
|
chat: { loading: false, loaded: false }
|
||||||
},
|
},
|
||||||
ajaxCallsInProgress: 0
|
ajaxCallsInProgress: 0
|
||||||
|
|
Loading…
Reference in New Issue