// Remove the session of this user
sessions.remove(user.toString());
}
private void sendQuestion(Message message, ChatbotSession session, int position) {
FormElement field = getForm().getFormElementAt(position);
if (field == null) {
return;
}
if (field.getAnswerType() == WorkgroupForm.FormEnum.hidden) {
// Auto accept hidden fields
Message fakeMessage = message.createCopy();
StringBuilder builder = new StringBuilder();
for (Iterator<String> it=field.getAnswers().iterator(); it.hasNext();) {
builder.append(it.next());
if (it.hasNext()) {
builder.append("/");
}
}
fakeMessage.setBody(builder.toString());
// Set that we are currently waiting for a response to the next question
session.setCurrentSubstep(position);
// Simulate that the user sent this message (with the hidden field)
onMessage(session, fakeMessage);
}
String text = field.getLabel();
if (field.getAnswerType() == WorkgroupForm.FormEnum.radio_button ||
field.getAnswerType() == WorkgroupForm.FormEnum.dropdown_box ||
field.getAnswerType() == WorkgroupForm.FormEnum.checkbox) {
// Append the options to the message body
if (!field.getAnswers().isEmpty()) {
StringBuilder builder = new StringBuilder(text);
builder.append(" [");
builder.append(Request.encodeMetadataValue(field.getAnswers()));
builder.append("]");
text = builder.toString();
}
}
sendReply(message, text);