Kommunicate-io/Kommunicate-Android-Chat-SDK

metadata is not passed to the payload of dialogflow webhook request

ndemir opened this issue · 10 comments

Hi,
I did a chatbot integration with dialogflow.
My dialogflow bot also has webhook integration.
When I use the following code; I don't see the metadata and the user information passed to payload from kommunicate to dialogflow webhook.

Is the following code wrong or is there a configuration that I did not do or is there an isse on kommunicate server-side?

        new KmConversationBuilder(this.activityContext)
                .setSkipConversationList(true)
                .setSingleConversation(true)
                .setBotIds(botIds)
                .setMessageMetadata(this.chatContext)
                .setKmUser(user)
                .launchConversation(new KmCallback() {
            @Override
            public void onSuccess(Object message) {
                System.out.println("onSuccess");
                System.out.println(message);
            }

            @Override
            public void onFailure(Object error) {
                System.out.println("onFailure");
                System.out.println(error);
            }
        });

@devashishmamgain , thanks for your comment.
I tested it and it is not working.
I verified that I am passing the information correctly because I can see the details on Kommunicate UI correctly. I attached the screenshot.
The problem is; this metadata is not passed to the webhook that is configured in dialogflow.
screenshot

Got it, let me check and get back to you

@ndemir You can set the key KM_CHAT_CONTEXT as below use setting and pass the meta data this data will go in each and every message users sends in chat :

  Map<String,String> metadata1 = new HashMap<>();
  metadata.put("KM_CHAT_CONTEXT","Value");
  ApplozicClient.getInstance(MainActivity.this).setMessageMetaData(metadata1);

@ndemir can you share the logs coming when you send a message?

Hi @Sunilkumarr and @devashishmamgain ,

Here is the log I see on Android Studio, as you can see, it seems the metadata is being sent from the device:

I/MessageClientService: Sending message to server: {"applicationId":"xxx","attDownloadInProgress":false,"canceled":false,"clientGroupId":"xxx-lftqz","connected":false,"contactIds":"","contentType":0,"createdAtTime":1570542204146,"delivered":false,"deviceKey":"xxx-8ea6-4d8e-99e2-1a4890308412","groupId":xxx,"hidden":false,"key":"xxxxx-xxx","message":"xxx","metadata":{"a":"b","userId":"y@y.com","KM_CHAT_CONTEXT":"Value"},"read":true,"replyMessage":0,"sendToDevice":false,"sent":true,"sentMessageTimeAtServer":0,"sentToServer":true,"shared":false,"source":2,"status":1,"storeOnDevice":true,"type":5,"userKey":"xxx-xxxx"}

And, here is the log I see on webhook, and I don't see the metadata in the payload:
"payload": {\n "botId": "xxx-lftqz",\n "groupId": "xxxx",\n "messageSource": "2",\n "applicationId": "xxxxxxx",\n "attachments": []\n }

@devashishmamgain, yes.
here it is:
"originalDetectIntentRequest": {\n "payload": {\n "botId": "xxx-lftqz",\n "groupId": "xxx",\n "messageSource": "2",\n "applicationId": "xxxx",\n "attachments": []\n }\n },\n

@ndemir You can use the below code to send the data to dialogflow and let us know if you face any issue.

import org.json.JSONObject;

     // JSON object key value pass the details here 

    JSONObject object = new JSONObject();
            try {
                object.put("key","value1");
                object.put("key1","value2");
                object.put("key2","value3");

            } catch (JSONException e) {
                e.printStackTrace();
            }

            Map<String,String> metadata = new HashMap<>();
            metadata.put("KM_CHAT_CONTEXT",object.toString()); // Converted to json object to string and passed 

            if (KMUser.isLoggedIn(this.activityContext)) {
                ApplozicClient.getInstance(this.activityContext).setMessageMetaData(metadata);
            }

            new KmConversationBuilder(this.activityContext)
                    .setSkipConversationList(true)
                    .setSingleConversation(true)
                    .setBotIds(null)
                    .setKmUser(user)
                    **.setMessageMetadata(metadata)**
                    .launchConversation(new KmCallback() {
                        @Override
                        public void onSuccess(Object message) {
                            System.out.println("onSuccess");
                            System.out.println(message);
                        }

                        @Override
                        public void onFailure(Object error) {
                            System.out.println("onFailure");
                            System.out.println(error);
                        }
                    });

Thank you very much, it worked now.