Forcing a QiChatbot to reply to a phrase typed by the user.

Publié environ 1 an il y a par  Karageorgiou. geo

Publier un sujet
Non résolus
K
Karageorgiou. geo

Greetings, 


I am working on a Pepper application on android that uses a QiChatbot to communicate with users about minerals. I want to make the chatbot also available for on-screen use for people with hearing and/or speech impairment. So i am building a UI like facebook messenger. While I am able to get the reply from pepper and show it on the screen, I cannot find a way to force a String that I am getting from an EditText by the user to the chatbot. 

I have tried using:


Future<ReplyReaction> replyToFuture = chatbot.async().replyTo(userPhrase, localeEN);

and


Future<Void> acknowledgeHeardFuture = chatbot.async().acknowledgeHeard(userPhrase,localeEN);

but without success.



Below you can see the whole chat and chatbot setup: 

private QiChatbot buildQiChatbot() {
        Topic lexicon = TopicBuilder
                .with(qiContext)
                .withResource(R.raw.lexicon)
                .build();
        Topic topic_minerals = TopicBuilder
                .with(qiContext)
                .withResource(R.raw.topic_minerals)
                .build();
        Topic test = TopicBuilder
                .with(qiContext)
                .withResource(R.raw.test_topic)
                .build();


        List<Topic> topicList = new LinkedList<Topic>();
        topicList.add(test);
        //topicList.add(lexicon);
        //topicList.add(topic_minerals);

        chatbot = QiChatbotBuilder
                .with(qiContext)
                .withTopics(topicList)
                .withLocale(localeEN)
                .build();

        chatbot.addOnBookmarkReachedListener(bookmark -> {
            Log.i(TAG, "Bookmark " + bookmark.getName() + " reached.");

        });

        chatbot.addOnEndedListener(endReason -> {
            Log.i(TAG, "Chatbot ended for reason: " + endReason);
            chatFuture.requestCancellation();
        });

        return chatbot;
    }

    private Chat buildChat(QiChatbot chatbot) {
        chat = ChatBuilder
                .with(qiContext)
                .withChatbot(chatbot)
                .build();

        chat.addOnStartedListener(() -> {
            Log.i(TAG, "[CHAT] Chat started.");

        });
        chat.addOnListeningChangedListener(listening -> {
            if (listening) {
                Log.i(TAG, "[CHAT] Listening START.");
            } else {
                Log.i(TAG, "[CHAT] Listening END.");
            }

        });
        chat.addOnHeardListener(heardPhrase -> {
            Log.i(TAG, "[CHAT] Heard phrase: " + heardPhrase.getText());

        });
        chat.addOnNormalReplyFoundForListener(input -> {
            Log.i(TAG, "[CHAT] Reply found for user message: " + input.getText());
        });
        chat.addOnNoPhraseRecognizedListener(() -> {
            Log.i(TAG, "[CHAT] No phrase recognized.");
        });
        chat.addOnSayingChangedListener(sayingPhrase -> {
            if (!sayingPhrase.getText().isEmpty()) {
                Log.i(TAG, "[CHAT] Pepper Reply: " + sayingPhrase.getText());
                messageItemList.add(new MessageItem(LayoutRobot, R.drawable.icons8_user_100, sayingPhrase.getText()));
                messageAdapter.notifyDataSetChanged();
            }
        });
        chat.addOnFallbackReplyFoundForListener(input -> {
            Log.i(TAG, "[CHAT] Fallback Reply found for user message: " + input.getText());
        });
        chat.addOnNoReplyFoundForListener(input -> {
            Log.i(TAG, "[CHAT] NO Reply found for user message: " + input.getText());
        });
        return chat;
    }




private QiChatbot buildQiChatbot() {
        Topic lexicon = TopicBuilder
                .with(qiContext)
                .withResource(R.raw.lexicon)
                .build();
        Topic topic_minerals = TopicBuilder
                .with(qiContext)
                .withResource(R.raw.topic_minerals)
                .build();
        Topic test = TopicBuilder
                .with(qiContext)
                .withResource(R.raw.test_topic)
                .build();


        List<Topic> topicList = new LinkedList<Topic>();
        topicList.add(test);
        //topicList.add(lexicon);
        //topicList.add(topic_minerals);

        chatbot = QiChatbotBuilder
                .with(qiContext)
                .withTopics(topicList)
                .withLocale(localeEN)
                .build();

        chatbot.addOnBookmarkReachedListener(bookmark -> {
            Log.i(TAG, "Bookmark " + bookmark.getName() + " reached.");

        });

        chatbot.addOnEndedListener(endReason -> {
            Log.i(TAG, "Chatbot ended for reason: " + endReason);
            chatFuture.requestCancellation();
        });

        return chatbot;
    }

    private Chat buildChat(QiChatbot chatbot) {
        chat = ChatBuilder
                .with(qiContext)
                .withChatbot(chatbot)
                .build();

        chat.addOnStartedListener(() -> {
            Log.i(TAG, "[CHAT] Chat started.");

        });
        chat.addOnListeningChangedListener(listening -> {
            if (listening) {
                Log.i(TAG, "[CHAT] Listening START.");
            } else {
                Log.i(TAG, "[CHAT] Listening END.");
            }

        });
        chat.addOnHeardListener(heardPhrase -> {
            Log.i(TAG, "[CHAT] Heard phrase: " + heardPhrase.getText());

        });
        chat.addOnNormalReplyFoundForListener(input -> {
            Log.i(TAG, "[CHAT] Reply found for user message: " + input.getText());
        });
        chat.addOnNoPhraseRecognizedListener(() -> {
            Log.i(TAG, "[CHAT] No phrase recognized.");
        });
        chat.addOnSayingChangedListener(sayingPhrase -> {
            if (!sayingPhrase.getText().isEmpty()) {
                Log.i(TAG, "[CHAT] Pepper Reply: " + sayingPhrase.getText());
                messageItemList.add(new MessageItem(LayoutRobot, R.drawable.icons8_user_100, sayingPhrase.getText()));
                messageAdapter.notifyDataSetChanged();
            }
        });
        chat.addOnFallbackReplyFoundForListener(input -> {
            Log.i(TAG, "[CHAT] Fallback Reply found for user message: " + input.getText());
        });
        chat.addOnNoReplyFoundForListener(input -> {
            Log.i(TAG, "[CHAT] NO Reply found for user message: " + input.getText());
        });
        return chat;
    }


0 Votes


0 Commentaires

Connexion ou S'inscrire pour poster un commentaire