in src/components/Widget/index.js [144:180]
sendMessage(payload, text = '', when = 'always', tooltipSelector = false) {
const { dispatch, initialized, messages } = this.props;
const emit = () => {
const send = () => {
dispatch(emitUserMessage(payload));
if (text !== '') {
dispatch(addUserMessage(text, tooltipSelector));
} else {
dispatch(addUserMessage('hidden', tooltipSelector, true));
}
if (tooltipSelector) {
dispatch(closeChat());
showTooltip(true);
}
// Mark that first chat has started
dispatch(setFirstChatStarted());
// Set bot processing state when user sends a message
dispatch(setBotProcessing(true));
// Start 30-second timeout to reset bot processing if backend hangs
startBotProcessingTimeout(dispatch);
};
if (when === 'always') {
send();
} else if (when === 'init') {
if (messages.size === 0) {
send();
}
}
};
if (!initialized) {
this.initializeWidget(false);
dispatch(initialize());
emit();
} else {
emit();
}
}