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 inputconst response = await Interactions.send("BookTrip", userInput);
// Log chatbot responseconsole.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 );