Page updated Nov 11, 2023

Interact with bots

Send messages to bot

You can send a text message to chatbot backend with send() command. The method returns a promise that includes the chatbot response.

import { Interactions } from 'aws-amplify'; let userInput = "I want to reserve a hotel for tonight"; // Provide a bot name and user input const response = await Interactions.send("BookTrip", userInput); // Log chatbot response console.log(response.message);
1import { Interactions } from 'aws-amplify';
2
3let userInput = "I want to reserve a hotel for tonight";
4
5// Provide a bot name and user input
6const response = await Interactions.send("BookTrip", userInput);
7
8// Log chatbot response
9console.log(response.message);

Display end of chat message

You can use onComplete() method to register a function to catch errors or chatbot confirmations when the session successfully ends.

const handleComplete = function (err, confirmation) { if (err) { alert('bot conversation failed'); return; } alert('done: ' + JSON.stringify(confirmation, null, 2)); return 'Trip booked. Thank you! What would you like to do next?'; } Interactions.onComplete(botName, handleComplete );
1const handleComplete = function (err, confirmation) {
2 if (err) {
3 alert('bot conversation failed');
4 return;
5 }
6 alert('done: ' + JSON.stringify(confirmation, null, 2));
7
8 return 'Trip booked. Thank you! What would you like to do next?';
9}
10
11Interactions.onComplete(botName, handleComplete );