Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send Data from Android to BlueMix #5

Closed
nizamudeenms opened this issue Jun 5, 2017 · 2 comments
Closed

Send Data from Android to BlueMix #5

nizamudeenms opened this issue Jun 5, 2017 · 2 comments
Assignees

Comments

@nizamudeenms
Copy link

nizamudeenms commented Jun 5, 2017

Hi,
Your Code is very useful to create a bot application, thanks for sharing.
Am unable to find a way to send the data from Android Application to Blue Mix server.

How am trying to send the value from android application.


private void sendMessage() {

        final String inputmessage = this.inputMessage.getText().toString().trim();
        if (!this.initialRequest) {
            Message inputMessage = new Message();
            inputMessage.setMessage(inputmessage);
            inputMessage.setId("1");
//Trying to set values for context here
            inputMessage.setFines("999");
            messageArrayList.add(inputMessage);
        } else {
            Message inputMessage = new Message();
            inputMessage.setMessage(inputmessage);
            inputMessage.setId("100");

            this.initialRequest = false;
            Toast.makeText(getApplicationContext(), "Tap on the message for Voice", Toast.LENGTH_LONG).show();

        }

        this.inputMessage.setText("");

        mAdapter.notifyDataSetChanged();

        Thread thread = new Thread(new Runnable() {
            public void run() {
                try {
                    ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_02_03);
                    service.setUsernameAndPassword("senate", "password");

                    context.put("1",inputmessage);

                    MessageRequest newMessage = new MessageRequest.Builder().inputText(inputmessage).context(context).build();

                    MessageResponse response = service.message("workspace", newMessage).execute();

                    //Passing Context of last conversation
                    if (response.getContext() != null) {
                        context = response.getContext();
                    }
                    Message outMessage = new Message();
                    if (response != null) {
                        if (response.getOutput() != null && response.getOutput().containsKey("text")) {
                            ArrayList responseList = (ArrayList) response.getOutput().get("text");
                            Log.i("responseList", responseList.get(0).toString());
                            if (null != responseList && responseList.size() > 0) {
                                outMessage.setMessage((String) responseList.get(0));
                                context = response.getContext();
//Trying to set values for context here
                                outMessage.setFines("200");
                                outMessage.setId("2");
                            }
                            messageArrayList.add(outMessage);
                        }

                        runOnUiThread(new Runnable() {
                            public void run() {
                                mAdapter.notifyDataSetChanged();
                                if (mAdapter.getItemCount() > 1) {
                                    recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, null, mAdapter.getItemCount() - 1);
                                }
                            }
                        });
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
    }


I want evaluate this reply using $var in Blue Mix conversation and respond accordingly.

@VidyasagarMSC
Copy link
Owner

@nizamudeenms What data are you referring to? Can you highlight the line number in the code?

@nizamudeenms
Copy link
Author

I mean my own data retrieved from Database

EG: in node js you send data like this ....


var ConversationV1 = require('watson-developer-cloud/conversation/v1');

var conversation = new ConversationV1({
  username: 'username',
  password: 'password', 
  path: { workspace_id: 'workspaceID' },  
  version_date: '2017-31-05'
});

var context; 

conversation.message({}, processResponse);


function processResponse(err, response) {
  if (err) {
    console.error(err); 
    return;
  }
  
  if (response.output.text.length != 0) {
      	console.log(response.output.text[0]);
//	console.log(response);

	if( response.output.text[0].indexOf("Checking traffic fines") > -1 || response.output.text[0].indexOf("checking traffic fines") > -1 ) {
		console.log("You have 600 Qatari Riyals of Traffic Fines");
		context = response.context;
		context.fines = "yes";

	 	conversation.message(
		{
			input: {},
			context: context
		}
		,processResponse
		);			
	}

	context = response.context; 
  }
}

var stdin = process.openStdin();

stdin.addListener("data", function(d) {
    // note:  d is an object, and when converted to a string it will
    // end with a linefeed.  so we (rather crudely) account for that  
    // with toString() and then trim() 
    console.log("you entered: [" + 
        d.toString().trim() + "]");

    conversation.message(

		{
  			input: {text: d.toString().trim()},
			context: context 
		}

		, processResponse); 

  });

In the above code, this block is validating if user has fines, appends 'fines' variable to context and sends 'fines' variable in the Blumix server. If I run this node js code in local console its giving the the proper output but I don't know how to convert this code to java.

if( response.output.text[0].indexOf("Checking traffic fines") > -1 || response.output.text[0].indexOf("checking traffic fines") > -1 ) {
console.log("You have 600 Qatari Riyals of Traffic Fines");
context = response.context;
context.fines = "yes";
conversation.message(
{
input: {},
context: context
}
,processResponse
);

In my case the fines are retrieved from database and sent to blue mix.
I want to know how to send data 'fines' from java ... It should be read by blue mix....

Please tell me how can I append a variable 'fine' in java context and send it to blue mix in java.

It will better if you give me your mobile number to call you. . I have mailed you please share mobile no in mail...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants