Multi-threaded chat

Asked

Viewed 87 times

1

Guys I’m developing a chat bot, the question with the answer that the bot gives is all right, my problem is when more than one person comes in contact with the chat, he is treating as if both are one, i believe the problem lies in the way I am handling the requests the user makes.

this is my managedBeam

    public String submit(){
        System.out.println("====submit======");

        getInteracoes().add(new InteracaoChat(1, userInput,Util.dataFormatada()));
        //realiza interaçao com o chat
        setBotOutput(new RealizaPerguntBot().realizaPergunta(userInput));

        return "";
    }


public class RealizaPerguntBot {
    /**
     * metodo responsavel por criar conexao com o watson e devolver uma resposta adequada para a pergunta realizada
     * 
     * @param pergunta
     * @return resposta
     */

    /**
     * O contexto é onde a conversa está no momento da interação, o contexto inicia como nulo pois é o inicio da conversa, a medida que vai 
     * encaminhando a conversa o contexto irá recebendo um novo valor, caso assumir nulo novamente a conversa irá voltar ao inicio
     */
    static Map<String, Object> context =  null;

    public String realizaPergunta(String pergunta){
//      
        /**
         * Service é uma classe nativa do watson, recebe a data (versão) do conversation
         */
        ConversationService service = new ConversationService(ConstantesWatson.DATE_VERSION_CONVERSATION);

        /*
         * configura o servico, recebe o usuario e a senha 
         * */
        service.setUsernameAndPassword(ConstantesWatson.USER_NAME_CONVERSATION, ConstantesWatson.PASSWORD_CONVERSATION);

        /**
         * newMesage é ai que será feito a interação do usuário com o bot, é passado a pergunta(interação) que o usuário fez ao bot, é passado o contexto
         * para que o bot saiba onde a conversa parou
         */
        MessageRequest newMessage = new MessageRequest.Builder().inputText(pergunta).context(context).build();



        String workspaceId = ConstantesWatson.WORKSPACE_ID_CONVERSATION;
        /**
         * Response recebe a resposta do bot com base na pergunta feita, é necessário passar o worksapeceid e a pergunta realizada pelo usuario
         */
        MessageResponse response = service.message(workspaceId, newMessage).execute();
        //recebe o novo valor do contexto.
        context = response.getContext();



        return new TrataRespostaJson().trataResponstaJson(response.toString());
    }

I would like to know from you how I would solve this problem, whether the thread implementation would solve the problem, if that is, tell me a more appropriate way to do.

Grateful

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.