skip to Main Content

enter image description here
why my bot is not responding


Not Getting reply From Bot while running the app on a device -Using Brain Shop API Android Studio in my android studio it doesn’t shoes any error but while i am running the app i send a message but didn’t get reply from bot.


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chatbot);
        chatsRV = findViewById(R.id.idRVChats);
        userMsgEdt = findViewById(R.id.idEdtMessage);
        sendMsgFAB = findViewById(R.id.idFABSend);
        chatsModalArrayList = new ArrayList<>();
        chatRVAdapter = new ChatRVAdapter(chatsModalArrayList,this);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        chatsRV.setLayoutManager(manager);
        chatsRV.setAdapter(chatRVAdapter);
        sendMsgFAB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (userMsgEdt.getText().toString().isEmpty()){
                    Toast.makeText(chatbot.this, "please enter your message",Toast.LENGTH_SHORT).show();
                    return;
                }

                getResponse(userMsgEdt.getText().toString());
                if(userMsgEdt.length()>0) {
                    userMsgEdt.setText(null);
                }
            }
        });



    }
    private void getResponse(String message){
        chatsModalArrayList.add(new ChatsModal( message,USER_KEY));
        chatRVAdapter.notifyDataSetChanged();
        String url = "http://api.brainshop.ai/get?bid=166135&key=HutlT9ZgXWrPpz3o&uid=[uid]&msg="+message;
        String BASE_URL = "http://api.brainshop.ai/";
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetrofitAPI retrofitAPI = retrofit.create(RetrofitAPI.class);
        Call<MsgModal> call = retrofitAPI.getMessage(url);
        call.equals(new Callback<MsgModal>() {
            @Override
            public void onResponse(Call<MsgModal> call, Response<MsgModal> response) {
                if(response.isSuccessful()){
                    MsgModal modal = response.body();
                    chatsModalArrayList.add(new ChatsModal(modal.getCnt(),BOT_KEY));
                    chatRVAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(Call<MsgModal> call, Throwable t) {
                chatsModalArrayList.add(new ChatsModal("please revert your question",BOT_KEY));
                chatRVAdapter.notifyDataSetChanged();

            }
        });



    }

2

Answers


  1. me too i had this probleme you have just change the url from :
    String url = "http://api.brainshop.ai/get?bid=166135&key=HutlT9ZgXWrPpz3o&uid=[uid]&msg="+message
    to

    String url = "http://api.brainshop.ai/get?bid=166135&key=HutlT9ZgXWrPpz3o&uid=uid&msg="+message
    

    remove [] from uid

    Login or Signup to reply.
  2. add this line in the manifest file

    <application>
    android:usesCleartextTraffic="true" 
    </application
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search