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