Topic & TopicStatus


level_1


Topic

A Topic represents a conversational topic for a QiChatbot. It groups together different rules defining Human-robot verbal interactions.

See also API doc: Topic.

TopicStatus

A TopicStatus allows you to read and write the status of a Topic.

Each Topic can be disabled: its rules will not be matched and the robot will not say proposals from those either.

At most one Topic can be focused at a time: it means this topic is the one where a rule was matched last.

See also API doc: TopicStatus.

How to use it

Configuring a QiChatbot

Build a Topic from a topic file (.top) and create a QiChatbot with it:

val topic: Topic = TopicBuilder.with(qiContext)
                          .withResource(R.raw.animals)
                          .build()

val qiChatbot: QiChatbot = QiChatbotBuilder.with(qiContext)
            .withTopic(topic)
            .build()
Topic topic = TopicBuilder.with(qiContext)
                          .withResource(R.raw.animals)
                          .build();

QiChatbot qiChatbot = QiChatbotBuilder.with(qiContext)
            .withTopic(topic)
            .build();

Retrieving topics

Get all the topics contained in a QiChatbot:

val qiChatbot: QiChatbot = ...
val topics: List<Topic> = qiChatbot.topics
QiChatbot qiChatbot = ...;
List<Topic> topics = qiChatbot.getTopics();

Controlling a Topic status

Create a TopicStatus from a Topic. This TopicStatus will be able to read and write the specified Topic status:

val topic: Topic = ...
val topicStatus: TopicStatus = qiChatbot.topicStatus(topic)

topicStatus.enable = false
val isEnabled: Boolean = topicStatus.enabled
topicStatus.addOnEnabledChangedListener { enabled -> Log.i(TAG, "onEnabledChanged: $enabled") }

val isFocused: Boolean = topicStatus.focused
topicStatus.addOnFocusedChangedListener { focused ->Log.i(TAG, "onFocusedChanged: $focused") }
Topic topic = ...;
TopicStatus topicStatus = qiChatbot.topicStatus(topic);

topicStatus.setEnabled(false);
Boolean isEnabled = topicStatus.getEnabled();
topicStatus.addOnEnabledChangedListener(enabled -> Log.i(TAG, "onEnabledChanged: " + enabled));

Boolean isFocused = topicStatus.getFocused();
topicStatus.addOnFocusedChangedListener(focused -> Log.i(TAG, "onFocusedChanged: " + focused));