Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static *newChat(action: ChatAction>): Iterable {
const { documentId, resolver } = action.payload;
// Create a new webchat store for this documentId
yield put(webChatStoreUpdated(documentId, createWebChatStore()));
// Each time a new chat is open, retrieve the speech token
// if the endpoint is speech enabled and create a bound speech
// pony fill factory. This is consumed by WebChat...
yield put(webSpeechFactoryUpdated(documentId, undefined)); // remove the old factory
const conversationId = yield select(getConversationIdFromDocumentId, documentId);
// Try the bot file
let endpoint: IEndpointService = yield select(getEndpointServiceByDocumentId, documentId);
// Not there. Try the service
if (!endpoint) {
try {
const serverUrl = yield select((state: RootState) => state.clientAwareSettings.serverUrl);
const endpointResponse: Response = yield ConversationService.getConversationEndpoint(serverUrl, conversationId);
if (!endpointResponse.ok) {
const error = yield endpointResponse.json();
throw new Error(error.error.message);
}
return ({ dispatch }) => next => ({ cardAction, getSignInUrl }) => {
const { displayText, text, type, value } = cardAction;
switch (type) {
case 'imBack':
if (typeof value === 'string') {
// TODO: [P4] Instead of calling dispatch, we should move to dispatchers instead for completeness
dispatch(sendMessage(value, 'imBack'));
} else {
throw new Error('cannot send "imBack" with a non-string value');
}
break;
case 'messageBack':
dispatch(sendMessageBack(value, text, displayText));
break;
case 'postBack':
dispatch(sendPostBack(value));
break;
return ({ dispatch }) => next => ({ cardAction, getSignInUrl }) => {
const { displayText, text, type, value } = cardAction;
switch (type) {
case 'imBack':
if (typeof value === 'string') {
// TODO: [P4] Instead of calling dispatch, we should move to dispatchers instead for completeness
dispatch(sendMessage(value, 'imBack'));
} else {
throw new Error('cannot send "imBack" with a non-string value');
}
break;
case 'messageBack':
dispatch(sendMessageBack(value, text, displayText));
break;
case 'postBack':
dispatch(sendPostBack(value));
break;
case 'call':
case 'downloadFile':
case 'openUrl':
case 'playAudio':
case 'playVideo':
case 'showImage':
window.open(value);
break;
if (typeof value === 'string') {
// TODO: [P4] Instead of calling dispatch, we should move to dispatchers instead for completeness
dispatch(sendMessage(value, 'imBack'));
} else {
throw new Error('cannot send "imBack" with a non-string value');
}
break;
case 'messageBack':
dispatch(sendMessageBack(value, text, displayText));
break;
case 'postBack':
dispatch(sendPostBack(value));
break;
case 'call':
case 'downloadFile':
case 'openUrl':
case 'playAudio':
case 'playVideo':
case 'showImage':
window.open(value);
break;
case 'signin': {
// TODO: [P3] We should prime the URL into the OAuthCard directly, instead of calling getSessionId on-demand
// This is to eliminate the delay between window.open() and location.href call
const memoizedStore = useMemo(() => store || createStore(), [store]);
useEffect(() => {
dispatch(setLanguage(locale));
}, [dispatch, locale]);
useEffect(() => {
dispatch(setSendTimeout(sendTimeout));
}, [dispatch, sendTimeout]);
useEffect(() => {
dispatch(setSendTypingIndicator(!!patchedSendTypingIndicator));
}, [dispatch, patchedSendTypingIndicator]);