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.
1import { Interactions } from 'aws-amplify';2
3let userInput = "I want to reserve a hotel for tonight";4
5// Provide a bot name and user input6const response = await Interactions.send("BookTrip", userInput);7
8// Log chatbot response9console.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.
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 );