Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
791 B
0
Indexable
Never
import ai.api.AIConfiguration;
import ai.api.AIDataService;
import ai.api.model.AIRequest;
import ai.api.model.AIResponse;

// Initialize Dialogflow API
AIConfiguration configuration = new AIConfiguration("YOUR_CLIENT_ACCESS_TOKEN",
        AIConfiguration.SupportedLanguages.English);

AIDataService dataService = new AIDataService(configuration);

// Function to send user input to Dialogflow and receive a response
public String sendMessageToDialogflow(String userInput) {
    AIRequest request = new AIRequest(userInput);
    try {
        AIResponse response = dataService.request(request);
        return response.getResult().getFulfillment().getSpeech();
    } catch (Exception e) {
        e.printStackTrace();
        return "Sorry, I'm having trouble understanding you.";
    }
}