How to use @aws-amplify/interactions - 10 common examples

To help you get started, we’ve selected a few @aws-amplify/interactions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.tsx View on Github external
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;
	}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.tsx View on Github external
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 },
				],
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.tsx View on Github external
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));
		}
	}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.tsx View on Github external
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));
		}
	}
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.jsx View on Github external
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;
    }
github aws-amplify / amplify-js / packages / aws-amplify-react-native / src / Interactions / ChatBot.js View on Github external
);

		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,
			},
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.jsx View on Github external
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;
        
    }
github aws-amplify / amplify-js / packages / aws-amplify-react-native / src / Interactions / ChatBot.js View on Github external
{ 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 },
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.jsx View on Github external
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));
        }
    }
github aws-amplify / amplify-js / packages / aws-amplify-react / src / Interactions / ChatBot.jsx View on Github external
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));
        }
    }

@aws-amplify/interactions

Interactions category of aws-amplify

Apache-2.0
Latest version published 8 days ago

Package Health Score

98 / 100
Full package analysis

Popular @aws-amplify/interactions functions

Similar packages