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.
src/App.tsx
import { Interactions } from '@aws-amplify/interactions';
const userInput = "I want to reserve a hotel for tonight";
// Provide a bot name and user inputconst response = await Interactions.send({ botName: "TheBotName", message: 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.
src/App.tsx
import { Interactions } from '@aws-amplify/interactions';
Interactions.onComplete({ botName: "TheBotName", callback: (error?: Error, completion?: {[key: string]: any}) => { if (error) { alert('bot conversation failed'); } else if (completion) { console.debug('done: ' + JSON.stringify(completion, null, 2)); alert('Trip booked. Thank you! What would you like to do next?'); } }});