WideChat / Rocket.Chat

Have your own Slack like online chat, built with Meteor.
https://rocket.chat/
Other
3 stars 1 forks source link

[BUG] mobile apps still showing no token from customFields #925

Open ear-dev opened 3 years ago

ear-dev commented 3 years ago

debug by providing the user meta data from the RC database. database.rocketchat_room.visitor.livechat_data

could this be performance issues on mobile? Chad to provide example roomID or user.... Eric will get the data from the database

ear-dev commented 3 years ago

{ "_id" : "y2MNJJopRMxRXkEra", "fname" : "xxxxxxx", "t" : "l", "v" : { "_id" : "TvuGLwrJSWxs7YPK5", "username" : "guest-69352", "token" : "07q1texjd9rhk8hwa2zm7te", "status" : "offline", "lastMessageTs" : ISODate("2021-09-09T00:27:06.808Z") }, "departmentId" : "XXkYv46G2f5pgfGkA", "servedBy" : { "_id" : "4w6SNb5y9iCJjtCiY", "username" : "liveagent" }, "default" : false, "ro" : false, "sysMes" : true, "msgs" : 44, "ts" : ISODate("2021-09-09T00:13:53.716Z"), "_updatedAt" : ISODate("2021-09-09T00:27:13.845Z"), "lm" : ISODate("2021-09-09T00:27:13.786Z"), "customFields" : { "welcomeEventSent" : true, "accessToken" : { "token" : "ya29.c.KqEBEAgLsFUqJE47ebqMZiN9gueneiEoaNbr2RlfafdA32DqkvuufK5NfG3y3R1c7KkM0tlrtpzMjr3DLmVF7x5YVh3dpvkTUR7ynuUNYomiFYUFF-7SKR8L9ur-az9jqd46MCOnzNpCq8cGcvjrBjTzxBTp_PebhzpOYGN04MUKONKJg33TZ0eEP5yOy3IX708PNjVkzH9IZLDDBqYqS41lp1U............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................", "expiration" : ISODate("2021-09-09T00:43:54.135Z") }, "reqButtonId" : "5733k000000Tfr5", "customDetail" : "{\"label\": \"BotTranscriptc\", \"value\": \"\\"No transcript available from messaging server\\"\", \"entityMaps\": [{\"entityName\": \"LiveChatTranscript\", \"fieldName\": \"BotTranscriptc\"}], \"transcriptFields\": [\"BotTranscript__c\"], \"displayToAgent\": true}", "isHandedOverFromDialogFlow" : true, "fallbackCount" : 0 }, "usersCount" : 1, "cl" : false, "lastMessage" : { "t" : "livechat-close", "msg" : "Closed by visitor", "groupable" : false, "transcriptRequested" : false, "ts" : ISODate("2021-09-09T00:27:13.786Z"), "u" : { "_id" : "TvuGLwrJSWxs7YPK5", "username" : "guest-69352", "name" : "Robin Hall" }, "rid" : "y2MNJJopRMxRXkEra", "_id" : "uzaF6FrzNsQWsn5v5", "_updatedAt" : ISODate("2021-09-09T00:27:13.839Z"), "urls" : [ ], "mentions" : [ ], "channels" : [ ], "md" : [ { "type" : "PARAGRAPH", "value" : [ { "type" : "PLAIN_TEXT", "value" : "Closed by visitor" } ] } ] }, "metrics" : { "reaction" : { "fd" : ISODate("2021-09-09T00:14:05.756Z"), "ft" : 12.04, "tt" : 427.75399999999996 }, "response" : { "avg" : 21.945421052631577, "fd" : ISODate("2021-09-09T00:14:05.756Z"), "ft" : 1.15, "total" : 19, "tt" : 416.96299999999997 }, "v" : { "lq" : ISODate("2021-09-09T00:27:06.808Z") }, "servedBy" : { "lr" : ISODate("2021-09-09T00:27:13.786Z") }, "chatDuration" : 800.026 }, "closedAt" : ISODate("2021-09-09T00:27:13.742Z"), "closedBy" : { "_id" : "TvuGLwrJSWxs7YPK5", "username" : "guest-69352" }, "closer" : "visitor", "tags" : [ ], "responseBy" : { "_id" : "TvuGLwrJSWxs7YPK5", "username" : "guest-69352", "lastMessageTs" : ISODate("2021-09-09T00:27:13.843Z") } }

ear-dev commented 3 years ago

@ear-dev find the 'use_token' file that myViasat is using

chadgoss commented 3 years ago

token.tsx:

import React, { useContext, useState } from 'react';
import { Token } from 'res-apps-lib/build/types/mv';
import { TokenFetchAction, useTokenService, TokenType } from 'shared/services/auth';
import env from 'shared/env';

export interface TokenProviderType {
  token?: Token | null;
  tokenFetchAction?: TokenFetchAction | null;
  setToken: (token: Token | null) => void;
  logout: () => void;
  setLogout: (logout: () => void) => void;
  tokenType?: TokenType | null;
  setTokenType: (tokenType: TokenType) => void;
}

const initalFunc = (): void => {
  console.error('No provider for token!');
};
const Context = React.createContext<TokenProviderType>({
  token: null,
  tokenFetchAction: null,
  setToken: initalFunc,
  logout: initalFunc,
  setLogout: initalFunc,
  tokenType: 'MySSO',
  setTokenType: initalFunc,
});

const initialLogoutFunc = (): void => {
  console.error('Logout called before setLogout called!');
};
export const TokenProvider = ({ children }: { children: React.ReactNode }): JSX.Element => {
  const tokenService = useTokenService();
  const { token, setToken, tokenType, setTokenType } = tokenService;
  const tokenFetchAction = env.debug.skipLogin ? 'NONE' : tokenService.tokenFetchAction;
  const [logout, setLogout] = useState(() => initialLogoutFunc);

  if (env.debug.auth && env.debug.skipLogin) console.info('Skipping auth. Skip login enabled');

  return (
    <Context.Provider value={{ token, tokenFetchAction, setToken, logout, setLogout, tokenType, setTokenType }}> 
      {children}
    </Context.Provider>
  );  
};

export const useToken = (): TokenProviderType => useContext(Context);
ear-dev commented 2 years ago

@Shailesh351 even after Marks latest attempt to resolve this issue in the integration script we are still seeing the same volume of missing appName/token in prod. Now that you have access to the myViasat repo maybe you can take a look and find the real solution? Thanks!

I think I would prioritize this one first. It will also give you some experience working on the myViasat repo before integrating our micro-frontend eventually.

ear-dev commented 2 years ago

Wiki from the viasat SSO team about api calls and oauth2 flow: https://wiki.viasat.com/display/IAM/OAuth+Example

ear-dev commented 2 years ago

Debugging strategy with elasticsearch?

logpoint to discover if some users are reaching our bot outside of the myViasat app entirely?

chadgoss commented 2 years ago

@Shailesh351 some example us residential sessions with missing appName and token 6JHNSGtskWHyDXNMv 73pdFu75TcxKsESNC 8hieRiZ3z4oZgDWw6 8nvgNAgMxdYT5QeXx B8YQgPPwxC9hfvxJa J53NnkTkrZ5KeTd8w Pp3bekA3pqCdR6zSv WYAHyvFYiNppfvB7K j4npHvCnxBKSgSqCe sEDt4AENuMXWRikZE t54DLTBHkdudK8WmD vo6tsEgWir5CjTEJy zP6dwy2gCwcEQBw7z

example fulfillment log point, note empty appName and token: Webhook Request: {'responseId': 'db02e487-71f9-4946-b600-93791cfd0d5e-278dc18a', 'queryResult': {'queryText': 'Welcome', 'action': 'load_subscriber_info', 'parameters': {'roomId': 'zP6dwy2gCwcEQBw7z', 'visitorToken': 'c52c39f87e0eb1e6eda5b1644ccb0264fd0db0284f0c7fdc9d66a92903d552d7', 'appName': '', 'token': ''}

ear-dev commented 2 years ago

NOTE: setting of custom field relies on receiving a refresh token.

ear-dev commented 2 years ago

@chadgoss enable logging on the CX side? Could this be a case where CX or fulfillment is dropping this? Please provide Shailesh with stackdriver access so he can debug.

chadgoss commented 2 years ago

@Shailesh351 Here are gcp logs for an example production session with a missing appName and token

packet 1: RC-->DF

{
insertId: "mhdyl9filnjg4"
labels: {
protocol: "V2"
request_id: "478706b7-6045-4e3b-a499-99a21f099cd6-37284719"
type: "dialogflow_request"
}
logName: "projects/chatbot-prod-228818/logs/dialogflow_agent"
receiveTimestamp: "2022-03-23T16:01:50.689653497Z"
resource: {
labels: {
project_id: "chatbot-prod-228818"
}
type: "global"
}
severity: "INFO"
textPayload: "Dialogflow Request : {"session":"BAyMYCDv3w5AEF3Hf","query_input":"{\n  \"event\": {\n    \"name\": \"Welcome\",\n    \"parameters\": {\n      \"roomId\": \"BAyMYCDv3w5AEF3Hf\",\n      \"visitorToken\": \"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\"\n    }\n  }\n}","timezone":"America/New_York"}"
timestamp: "2022-03-23T16:01:50.464Z"
trace: "BAyMYCDv3w5AEF3Hf"
}

packet 2: DF-->Fulfillment

Dialogflow fulfillment request : {
  "responseId": "478706b7-6045-4e3b-a499-99a21f099cd6-37284719",
  "queryResult": {
    "queryText": "Welcome",
    "action": "load_subscriber_info",
    "parameters": {
      "roomId": "BAyMYCDv3w5AEF3Hf",
      "visitorToken": "da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13",
      "appName": "",
      "token": ""
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "How can I help you?",
    "fulfillmentMessages": [{
      "text": {
        "text": ["How can I help you?"]
      }
    }],
    "outputContexts": [{
      "name": "projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/welcome",
      "parameters": {
        "roomId": "BAyMYCDv3w5AEF3Hf",
        "visitorToken": "da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13",
        "appName": "",
        "appName.original": "",
        "token": "",
        "token.original": "",
        "roomId.original": "",
        "visitorToken.original": ""
      }
    }, {
      "name": "projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/__system_counters__",
      "parameters": {
        "no-input": 0.0,
        "no-match": 0.0,
        "roomId": "BAyMYCDv3w5AEF3Hf",
        "visitorToken": "da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13",
        "appName": "",
        "appName.original": "",
        "token": "",
        "token.original": "",
        "roomId.original": "",
        "visitorToken.original": ""
      }
    }],
    "intent": {
      "name": "projects/chatbot-prod-228818/agent/intents/732ca2a0-46f7-11ec-9f5a-0242ac110003",
      "displayName": "prechat_form"
    },
    "intentDetectionConfidence": 1.0,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "payload": {
    }
  },
  "session": "projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf"
}

packet 3: Fulfillment-->DF

Dialogflow fulfillment response : {
  "fulfillmentMessages": [{
    "text": {
      "text": ["I am unable to locate your account information."]
    }
  }, {
    "text": {
      "text": ["Please contact our Customer Care team by phone 24/7 at 1-855-463-9333."]
    }
  }, {
    "text": {
      "text": ["Please close this window to end your chat session."]
    }
  }, {
    "payload": {
      "action": {
        "name": "df_close_chat"
      }
    }
  }],
  "outputContexts": [{
    "name": "projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/chat_source_MyViasatWebAmer",
    "lifespanCount": 999,
    "parameters": {
      "app": "MyViasatWebAmer",
      "device_type": "",
      "page_url": ""
    }
  }, {
    "name": "projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/previous_intent_info",
    "lifespanCount": 999,
    "parameters": {
      "appName": "",
      "roomId": "BAyMYCDv3w5AEF3Hf",
      "token": "",
      "visitorToken": "da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13"
    }
  }],
  "followupEventInput": {
  }
}

packet 4: DF-->RC

Dialogflow Response : id: "478706b7-6045-4e3b-a499-99a21f099cd6-37284719"
lang: "en"
session_id: "BAyMYCDv3w5AEF3Hf"
timestamp: "2022-03-23T16:01:50.467707Z"
result {
  source: "agent"
  resolved_query: "Welcome"
  action: "load_subscriber_info"
  score: 1.0
  parameters {
    fields {
      key: "appName"
      value {
        string_value: ""
      }
    }
    fields {
      key: "roomId"
      value {
        string_value: "BAyMYCDv3w5AEF3Hf"
      }
    }
    fields {
      key: "token"
      value {
        string_value: ""
      }
    }
    fields {
      key: "visitorToken"
      value {
        string_value: "da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13"
      }
    }
  }
  contexts {
    name: "chat_source_myviasatwebamer"
    lifespan: 999
    parameters {
      fields {
        key: "app"
        value {
          string_value: "MyViasatWebAmer"
        }
      }
      fields {
        key: "device_type"
        value {
          string_value: ""
        }
      }
      fields {
        key: "page_url"
        value {
          string_value: ""
        }
      }
    }
  }
  contexts {
    name: "previous_intent_info"
    lifespan: 999
    parameters {
      fields {
        key: "appName"
        value {
          string_value: ""
        }
      }
      fields {
        key: "roomId"
        value {
          string_value: "BAyMYCDv3w5AEF3Hf"
        }
      }
      fields {
        key: "token"
        value {
          string_value: ""
        }
      }
      fields {
        key: "visitorToken"
        value {
          string_value: "da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13"
        }
      }
    }
  }
  metadata {
    intent_id: "732ca2a0-46f7-11ec-9f5a-0242ac110003"
    webhook_response_time: 202
    intent_name: "prechat_form"
    webhook_used: "false"
    webhook_for_slot_filling_used: "false"
    is_fallback_intent: "false"
  }
  fulfillment {
    speech: "How can I help you?"
    messages {
      type {
        number_value: 0.0
      }
      speech {
        string_value: "I am unable to locate your account information."
      }
    }
    messages {
      type {
        number_value: 0.0
      }
      speech {
        string_value: "Please contact our Customer Care team by phone 24/7 at 1-855-463-9333."
      }
    }
    messages {
      type {
        number_value: 0.0
      }
      speech {
        string_value: "Please close this window to end your chat session."
      }
    }
    messages {
      payload {
        fields {
          key: "action"
          value {
            struct_value {
              fields {
                key: "name"
                value {
                  string_value: "df_close_chat"
                }
              }
            }
          }
        }
      }
      type {
        number_value: 4.0
      }
    }
  }
}
status {
  code: 200
  error_type: "success"
}
chadgoss commented 2 years ago
[
  {
    "textPayload": "Dialogflow Response : id: \"478706b7-6045-4e3b-a499-99a21f099cd6-37284719\"\nlang: \"en\"\nsession_id: \"BAyMYCDv3w5AEF3Hf\"\ntimestamp: \"2022-03-23T16:01:50.467707Z\"\nresult {\n  source: \"agent\"\n  resolved_query: \"Welcome\"\n  action: \"load_subscriber_info\"\n  score: 1.0\n  parameters {\n    fields {\n      key: \"appName\"\n      value {\n        string_value: \"\"\n      }\n    }\n    fields {\n      key: \"roomId\"\n      value {\n        string_value: \"BAyMYCDv3w5AEF3Hf\"\n      }\n    }\n    fields {\n      key: \"token\"\n      value {\n        string_value: \"\"\n      }\n    }\n    fields {\n      key: \"visitorToken\"\n      value {\n        string_value: \"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\"\n      }\n    }\n  }\n  contexts {\n    name: \"chat_source_myviasatwebamer\"\n    lifespan: 999\n    parameters {\n      fields {\n        key: \"app\"\n        value {\n          string_value: \"MyViasatWebAmer\"\n        }\n      }\n      fields {\n        key: \"device_type\"\n        value {\n          string_value: \"\"\n        }\n      }\n      fields {\n        key: \"page_url\"\n        value {\n          string_value: \"\"\n        }\n      }\n    }\n  }\n  contexts {\n    name: \"previous_intent_info\"\n    lifespan: 999\n    parameters {\n      fields {\n        key: \"appName\"\n        value {\n          string_value: \"\"\n        }\n      }\n      fields {\n        key: \"roomId\"\n        value {\n          string_value: \"BAyMYCDv3w5AEF3Hf\"\n        }\n      }\n      fields {\n        key: \"token\"\n        value {\n          string_value: \"\"\n        }\n      }\n      fields {\n        key: \"visitorToken\"\n        value {\n          string_value: \"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\"\n        }\n      }\n    }\n  }\n  metadata {\n    intent_id: \"732ca2a0-46f7-11ec-9f5a-0242ac110003\"\n    webhook_response_time: 202\n    intent_name: \"prechat_form\"\n    webhook_used: \"false\"\n    webhook_for_slot_filling_used: \"false\"\n    is_fallback_intent: \"false\"\n  }\n  fulfillment {\n    speech: \"How can I help you?\"\n    messages {\n      type {\n        number_value: 0.0\n      }\n      speech {\n        string_value: \"I am unable to locate your account information.\"\n      }\n    }\n    messages {\n      type {\n        number_value: 0.0\n      }\n      speech {\n        string_value: \"Please contact our Customer Care team by phone 24/7 at 1-855-463-9333.\"\n      }\n    }\n    messages {\n      type {\n        number_value: 0.0\n      }\n      speech {\n        string_value: \"Please close this window to end your chat session.\"\n      }\n    }\n    messages {\n      payload {\n        fields {\n          key: \"action\"\n          value {\n            struct_value {\n              fields {\n                key: \"name\"\n                value {\n                  string_value: \"df_close_chat\"\n                }\n              }\n            }\n          }\n        }\n      }\n      type {\n        number_value: 4.0\n      }\n    }\n  }\n}\nstatus {\n  code: 200\n  error_type: \"success\"\n}\n",
    "insertId": "mhdyl9filnjg5",
    "resource": {
      "type": "global",
      "labels": {
        "project_id": "chatbot-prod-228818"
      }
    },
    "timestamp": "2022-03-23T16:01:50.681322Z",
    "severity": "INFO",
    "labels": {
      "request_id": "478706b7-6045-4e3b-a499-99a21f099cd6-37284719",
      "protocol": "V2",
      "type": "dialogflow_response"
    },
    "logName": "projects/chatbot-prod-228818/logs/dialogflow_agent",
    "trace": "BAyMYCDv3w5AEF3Hf",
    "receiveTimestamp": "2022-03-23T16:01:50.689653497Z"
  },
  {
    "textPayload": "Dialogflow fulfillment response : {\n  \"fulfillmentMessages\": [{\n    \"text\": {\n      \"text\": [\"I am unable to locate your account information.\"]\n    }\n  }, {\n    \"text\": {\n      \"text\": [\"Please contact our Customer Care team by phone 24/7 at 1-855-463-9333.\"]\n    }\n  }, {\n    \"text\": {\n      \"text\": [\"Please close this window to end your chat session.\"]\n    }\n  }, {\n    \"payload\": {\n      \"action\": {\n        \"name\": \"df_close_chat\"\n      }\n    }\n  }],\n  \"outputContexts\": [{\n    \"name\": \"projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/chat_source_MyViasatWebAmer\",\n    \"lifespanCount\": 999,\n    \"parameters\": {\n      \"app\": \"MyViasatWebAmer\",\n      \"device_type\": \"\",\n      \"page_url\": \"\"\n    }\n  }, {\n    \"name\": \"projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/previous_intent_info\",\n    \"lifespanCount\": 999,\n    \"parameters\": {\n      \"appName\": \"\",\n      \"roomId\": \"BAyMYCDv3w5AEF3Hf\",\n      \"token\": \"\",\n      \"visitorToken\": \"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\"\n    }\n  }],\n  \"followupEventInput\": {\n  }\n}",
    "insertId": "170u0tcfimp64j",
    "resource": {
      "type": "global",
      "labels": {
        "project_id": "chatbot-prod-228818"
      }
    },
    "timestamp": "2022-03-23T16:01:50.677731Z",
    "severity": "INFO",
    "labels": {
      "protocol": "V2",
      "type": "conversation_response",
      "request_id": "478706b7-6045-4e3b-a499-99a21f099cd6-37284719"
    },
    "logName": "projects/chatbot-prod-228818/logs/dialogflow_agent",
    "trace": "BAyMYCDv3w5AEF3Hf",
    "receiveTimestamp": "2022-03-23T16:01:50.683334341Z"
  },
  {
    "textPayload": "Dialogflow fulfillment request : {\n  \"responseId\": \"478706b7-6045-4e3b-a499-99a21f099cd6-37284719\",\n  \"queryResult\": {\n    \"queryText\": \"Welcome\",\n    \"action\": \"load_subscriber_info\",\n    \"parameters\": {\n      \"roomId\": \"BAyMYCDv3w5AEF3Hf\",\n      \"visitorToken\": \"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\",\n      \"appName\": \"\",\n      \"token\": \"\"\n    },\n    \"allRequiredParamsPresent\": true,\n    \"fulfillmentText\": \"How can I help you?\",\n    \"fulfillmentMessages\": [{\n      \"text\": {\n        \"text\": [\"How can I help you?\"]\n      }\n    }],\n    \"outputContexts\": [{\n      \"name\": \"projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/welcome\",\n      \"parameters\": {\n        \"roomId\": \"BAyMYCDv3w5AEF3Hf\",\n        \"visitorToken\": \"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\",\n        \"appName\": \"\",\n        \"appName.original\": \"\",\n        \"token\": \"\",\n        \"token.original\": \"\",\n        \"roomId.original\": \"\",\n        \"visitorToken.original\": \"\"\n      }\n    }, {\n      \"name\": \"projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf/contexts/__system_counters__\",\n      \"parameters\": {\n        \"no-input\": 0.0,\n        \"no-match\": 0.0,\n        \"roomId\": \"BAyMYCDv3w5AEF3Hf\",\n        \"visitorToken\": \"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\",\n        \"appName\": \"\",\n        \"appName.original\": \"\",\n        \"token\": \"\",\n        \"token.original\": \"\",\n        \"roomId.original\": \"\",\n        \"visitorToken.original\": \"\"\n      }\n    }],\n    \"intent\": {\n      \"name\": \"projects/chatbot-prod-228818/agent/intents/732ca2a0-46f7-11ec-9f5a-0242ac110003\",\n      \"displayName\": \"prechat_form\"\n    },\n    \"intentDetectionConfidence\": 1.0,\n    \"languageCode\": \"en\"\n  },\n  \"originalDetectIntentRequest\": {\n    \"payload\": {\n    }\n  },\n  \"session\": \"projects/chatbot-prod-228818/agent/environments/PRODAmerRC/users/-/sessions/BAyMYCDv3w5AEF3Hf\"\n}",
    "insertId": "828386ffuuh96",
    "resource": {
      "type": "global",
      "labels": {
        "project_id": "chatbot-prod-228818"
      }
    },
    "timestamp": "2022-03-23T16:01:50.474152Z",
    "severity": "INFO",
    "labels": {
      "protocol": "V2",
      "type": "conversation_request",
      "request_id": "478706b7-6045-4e3b-a499-99a21f099cd6-37284719"
    },
    "logName": "projects/chatbot-prod-228818/logs/dialogflow_agent",
    "trace": "BAyMYCDv3w5AEF3Hf",
    "receiveTimestamp": "2022-03-23T16:01:50.480223755Z"
  },
  {
    "textPayload": "Dialogflow Request : {\"session\":\"BAyMYCDv3w5AEF3Hf\",\"query_input\":\"{\\n  \\\"event\\\": {\\n    \\\"name\\\": \\\"Welcome\\\",\\n    \\\"parameters\\\": {\\n      \\\"roomId\\\": \\\"BAyMYCDv3w5AEF3Hf\\\",\\n      \\\"visitorToken\\\": \\\"da5c216211e5bebb531049d7edc2fbe7a7506c4c9dc12af10b39a45a19b4af13\\\"\\n    }\\n  }\\n}\",\"timezone\":\"America/New_York\"}",
    "insertId": "mhdyl9filnjg4",
    "resource": {
      "type": "global",
      "labels": {
        "project_id": "chatbot-prod-228818"
      }
    },
    "timestamp": "2022-03-23T16:01:50.464Z",
    "severity": "INFO",
    "labels": {
      "protocol": "V2",
      "type": "dialogflow_request",
      "request_id": "478706b7-6045-4e3b-a499-99a21f099cd6-37284719"
    },
    "logName": "projects/chatbot-prod-228818/logs/dialogflow_agent",
    "trace": "BAyMYCDv3w5AEF3Hf",
    "receiveTimestamp": "2022-03-23T16:01:50.689653497Z"
  }
]
ear-dev commented 2 years ago

@Shailesh351 please propose a new location for the set.customField(appName) in the integration script. This way we can decouple appName from the refresh token issue and see if maybe we can isolate the failed code path.

Also please suggest a few new dummy/logPoint type customFields that we can sprinkle throughout the integration script so that maybe we can get a better handle on what is failing.

Shailesh351 commented 2 years ago

This is the code to decouple setting appName from token.

  useEffect(() => {
    if (isScriptLoaded) {
      setCustomFields([
        { name: 'appName', value: APP_NAME },
        { name: 'appVersion', value: packageJson.version },
      ]);
    }
  }, [isScriptLoaded]);

  useEffect(() => {
    if (isScriptLoaded && token?.accessToken) {
      setCustomFields([{ name: 'token', value: token?.accessToken ?? '' }]);

      setRocketChatDataAfterLoad();

      if (!isWeb) {
        restartMobileWidget();
        hidePrint();
      }
    }
  }, [token?.accessToken, isScriptLoaded]);
Shailesh351 commented 2 years ago

Created PR: https://git.viasat.com/ICAT/MyViasat/pull/1117 to decouple appName and add some log points as custom fields.

diff

Shells-MacBook-Pro:MyViasat shell$ git diff 0645b9f4...12576c3f
diff --git a/packages/shared/containers/rocketChat.tsx b/packages/shared/containers/rocketChat.tsx
index e222aa94..8fd80d47 100644
--- a/packages/shared/containers/rocketChat.tsx
+++ b/packages/shared/containers/rocketChat.tsx
@@ -109,6 +109,7 @@ const loadRocketChatScript = (
         setIsScriptLoaded(true);
       })
       .catch(err => {
+        setCustomFields([{ name: 'logPoint1', value: `loadRocketChatScript: err ${err} ` }]);
         console.error(err);
       });
   }
@@ -233,12 +234,48 @@ export const RocketChatProvider = ({ children }: { children: React.ReactNode }):
   const [isScriptLoaded, setIsScriptLoaded] = useState<boolean>(false);

   useEffect(() => {
-    if (isScriptLoaded && token?.accessToken) {
+    if (isScriptLoaded) {
       setCustomFields([
         { name: 'appName', value: APP_NAME },
-        { name: 'token', value: token?.accessToken ?? '' },
         { name: 'appVersion', value: packageJson.version },
       ]);
+    }
:...skipping...
diff --git a/packages/shared/containers/rocketChat.tsx b/packages/shared/containers/rocketChat.tsx
index e222aa94..8fd80d47 100644
--- a/packages/shared/containers/rocketChat.tsx
+++ b/packages/shared/containers/rocketChat.tsx
@@ -109,6 +109,7 @@ const loadRocketChatScript = (
         setIsScriptLoaded(true);
       })
       .catch(err => {
+        setCustomFields([{ name: 'logPoint1', value: `loadRocketChatScript: err ${err} ` }]);
         console.error(err);
       });
   }
@@ -233,12 +234,48 @@ export const RocketChatProvider = ({ children }: { children: React.ReactNode }):
   const [isScriptLoaded, setIsScriptLoaded] = useState<boolean>(false);

   useEffect(() => {
-    if (isScriptLoaded && token?.accessToken) {
+    if (isScriptLoaded) {
       setCustomFields([
         { name: 'appName', value: APP_NAME },
-        { name: 'token', value: token?.accessToken ?? '' },
         { name: 'appVersion', value: packageJson.version },
       ]);
+    }
+  }, [isScriptLoaded]);
+
+  useEffect(() => {
+    if (isScriptLoaded) {
+      if (!token?.accessToken) {
+        setCustomFields([
+          { name: 'logPoint2', value: 'useEffect(accessToken): RC Widget is loaded but accessToken is undefined' },
+        ]);
+      } else if (token?.accessToken == 'Error') {
+        setCustomFields([
+          {
+            name: 'logPoint3',
+            value: 'useEffect(accessToken): RC Widget is loaded but failed to get accessToken(Error)',
+          },
+        ]);
+      }
+    }
+
+    if (token?.accessToken) {
+      if (!isScriptLoaded) {
+        setCustomFields([
+          { name: 'logPoint4', value: 'useEffect(accessToken): Got token but RC Widget is not loaded yet' },
+        ]);
+      } else {
+        setCustomFields([
+          {
+            name: 'logPoint4',
+            value:
+              'useEffect(accessToken): Got token and RC Widget is loaded as well. If token and appName are still missing then that means issue at RC Widget side',
+          },
+        ]);
+      }
+    }
+
+    if (isScriptLoaded && token?.accessToken) {
+      setCustomFields([{ name: 'token', value: token?.accessToken ?? '' }]);

       setRocketChatDataAfterLoad();
Shailesh351 commented 2 years ago

Created PR https://git.viasat.com/ICAT/MyViasat/pull/1132 which fix earlier breaking changes for the web

ear-dev commented 2 years ago

Created PR https://git.viasat.com/ICAT/MyViasat/pull/1132 which fix earlier breaking changes for the web

This PR has been merged.... moving this story back into TODO so we can debug logs when they start coming in.

ear-dev commented 2 years ago

@Shailesh351 can you add the required customFields needed for debugging to our production server at chatbot.vega.viasat.com please? I'm not sure when this commit will make it into production, but we'll keep an eye on it. Thanks.

Shailesh351 commented 2 years ago

@ear-dev Done ✅