Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dialog: [
...this.state.dialog,
{ message: this.state.inputText, from: 'me' },
],
},
resolve
)
);
if (!Interactions || typeof Interactions.send !== 'function') {
throw new Error(
'No Interactions module found, please ensure @aws-amplify/interactions is imported'
);
}
const response = await Interactions.send(
this.props.botName,
this.state.inputText
);
this.setState({
// @ts-ignore
dialog: [
...this.state.dialog,
response && { from: 'bot', message: response.message },
],
inputText: '',
});
this.listItemsRef.current.scrollTop = this.listItemsRef.current.scrollHeight;
}
throw new Error(
'No Interactions module found, please ensure @aws-amplify/interactions is imported'
);
}
if (!this.state.continueConversation) {
return;
}
const interactionsMessage = {
content: this.state.audioInput,
options: {
messageType: 'voice',
},
};
const response = await Interactions.send(
this.props.botName,
interactionsMessage
);
this.setState(
{
lexResponse: response,
currentVoiceState: STATES.SPEAKING,
micText: STATES.SPEAKING.ICON,
micButtonDisabled: true,
dialog: [
...this.state.dialog,
// @ts-ignore
{ message: response.inputTranscript, from: 'me' },
// @ts-ignore
response && { from: 'bot', message: response.message },
],
componentDidMount() {
const { onComplete, botName } = this.props;
if (onComplete && botName) {
if (!Interactions || typeof Interactions.onComplete !== 'function') {
throw new Error(
'No Interactions module found, please ensure @aws-amplify/interactions is imported'
);
}
// @ts-ignore
Interactions.onComplete(botName, this.getOnComplete(onComplete, this));
}
}
componentDidUpdate(prevProps) {
const { onComplete, botName } = this.props;
if (botName && this.props.onComplete !== prevProps.onComplete) {
if (!Interactions || typeof Interactions.onComplete !== 'function') {
throw new Error(
'No Interactions module found, please ensure @aws-amplify/interactions is imported'
);
}
// @ts-ignore
Interactions.onComplete(botName, this.getOnComplete(onComplete, this));
}
}
if (!this.state.inputText) {
return;
}
await new Promise(resolve => this.setState({
dialog: [
...this.state.dialog,
{ message: this.state.inputText, from: 'me' },
]
}, resolve));
if (!Interactions || typeof Interactions.send !== 'function') {
throw new Error('No Interactions module found, please ensure @aws-amplify/interactions is imported');
}
const response = await Interactions.send(this.props.botName, this.state.inputText);
this.setState({
dialog: [...this.state.dialog, response && { from: 'bot', message: response.message }],
inputText: ''
});
this.listItemsRef.current.scrollTop = this.listItemsRef.current.scrollHeight;
}
);
let response;
if (voiceResponse === true) {
const interactionsMessage = {
content: this.state.inputText,
options: {
messageType: 'text',
},
};
response = await Interactions.send(
this.props.botName,
interactionsMessage
);
} else {
response = await Interactions.send(
this.props.botName,
this.state.inputText
);
}
this.setState(
{
dialog: [
...this.state.dialog,
response &&
response.message && { from: 'bot', message: response.message },
].filter(Boolean),
inputText: '',
inputEditable: true,
micText: MIC_BUTTON_TEXT.PASSIVE,
},
async lexResponseHandler() {
if (!Interactions || typeof Interactions.send !== 'function') {
throw new Error('No Interactions module found, please ensure @aws-amplify/interactions is imported');
}
if (!this.state.continueConversation) {
return;
}
const interactionsMessage = {
content: this.state.audioInput,
options: {
messageType: 'voice'
}
};
const response = await Interactions.send(this.props.botName, interactionsMessage);
this.setState({
lexResponse: response,
currentVoiceState: STATES.SPEAKING,
micText: STATES.SPEAKING.ICON,
micButtonDisabled: true,
dialog: [...this.state.dialog,
{ message: response.inputTranscript, from: 'me' },
response && { from: 'bot', message: response.message }],
inputText: ''
}, () => {
this.doneSpeakingHandler();
})
this.listItemsRef.current.scrollTop = this.listItemsRef.current.scrollHeight;
}
{ message: this.state.inputText, from: 'me' },
],
},
resolve
)
);
let response;
if (voiceResponse === true) {
const interactionsMessage = {
content: this.state.inputText,
options: {
messageType: 'text',
},
};
response = await Interactions.send(
this.props.botName,
interactionsMessage
);
} else {
response = await Interactions.send(
this.props.botName,
this.state.inputText
);
}
this.setState(
{
dialog: [
...this.state.dialog,
response &&
response.message && { from: 'bot', message: response.message },
componentDidMount() {
const {onComplete, botName} = this.props;
if(onComplete && botName) {
if (!Interactions || typeof Interactions.onComplete !== 'function') {
throw new Error('No Interactions module found, please ensure @aws-amplify/interactions is imported');
}
Interactions.onComplete(botName, this.getOnComplete(onComplete, this));
}
}
componentDidUpdate(prevProps) {
const {onComplete, botName} = this.props;
if (botName && this.props.onComplete !== prevProps.onComplete) {
if (!Interactions || typeof Interactions.onComplete !== 'function') {
throw new Error('No Interactions module found, please ensure @aws-amplify/interactions is imported');
}
Interactions.onComplete(botName, this.getOnComplete(onComplete, this));
}
}