Closed AaronKimLP closed 6 years ago
Hi @AaronKimLP,
As you figured out, there are two {type: "personal"}
objects because Transformer.js is manipulating the response payload of the .ams.userprofile.GetUserProfile
request.
The data associated with the user in our service can include two types of attributes:
In the current version of the UMS API authenticated data is returned as msg.body.authenticatedData
and unauthenticated data is returned as msg.body.privateData
. The manipulation performed by the SDK is intended to prepare it for the next version of the UMS API which will format the data differently. The idea is that once the payload of this response changes, implementations of the SDK will not need to change anything.
Hi @donmanguno , Thank you for your response.
So, how can I distinguish between the two personal types in my app? Whether there has a key "auth" in the hash?
And, in the next version of the UMS API, will only return one personal data? If I add some code to distinguish the personal types now, Do I need to change the code in the next version?
Hi @AaronKimLP,
Yes, the presence of the auth
key indicates the personalInfo that came from an authenticated source.
The SDK's current design is intended to ensure that no changes will be necessary when the UMS API is updated, but I will consult the appropriate product owners to verify that.
Sure. thanks.
@donmanguno
Hi @AaronKimLP
Nothing will change such that you will be affected.
Hi, I am using this messaging agent sdk now. And I have found one thing to confirm. When I use the "getProfile". I have got the following response.
[ { type: 'ctmrinfo', info: { customerId: 'line_89883808_Ud65445def1e33b45xxxxxxxxxxx', companyBranch: '1541765243' }, auth: {} }, { type: 'personal', personal: {}, auth: {} }, { type: 'personal', personal: { firstname: 'myname' } } ]
The question is why there have two personal ?
Also I have checked the following codes in /lib/Transformer.js . What's the difference between authenticatedData and privateData and msg.body.firstName ? Is there any documents about this?
'.ams.userprofile.GetUserProfile$Response': (msg) => { let SDEs = []; let authData = msg.body.authenticatedData; let privateData = msg.body.privateData || {}; if (authData && authData.lp_sdes) { msg.body.authenticatedData.lp_sdes.forEach(sde => { sde.auth = {}; SDEs.push(sde); }); } console.log(SDEs); let ctmrinfo = { type: 'ctmrinfo', info: {} }; if (privateData.mobileNum) { ctmrinfo.info.imei = privateData.mobileNum; } if (privateData.userId) { ctmrinfo.info.customerId = privateData.userId; } if (Object.keys(ctmrinfo.info).length > 0) { SDEs.push(ctmrinfo); } console.log(SDEs); let personalInfo = { type: 'personal', personal: {} }; if (msg.body.firstName) { personalInfo.personal.firstname = msg.body.firstName; } if (msg.body.lastName) { personalInfo.personal.lastname = msg.body.lastName; } if (privateData.email || privateData.mobileNum) { personalInfo.personal.contacts = [{ email: privateData.email, phone: privateData.mobileNum }]; } if (Object.keys(personalInfo.personal).length > 0) { SDEs.push(personalInfo); } console.log(SDEs); delete msg.body; msg.body = SDEs; return msg; },