Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Error: One or more required fields were not set on the message #24

Open
sherine-pt opened this issue Jun 7, 2018 · 8 comments
Open

Comments

@sherine-pt
Copy link

I am trying to implement the chatbase analytics for dialogflow agent using dialogflow google cloud function.

When I send the chatbase message independently using the sample nodejs function. It sends the message to chatbase without any issues and I can able to view the analytics in chatbase dashboard. But copied the same code to dialogflow cloud function it throws the following error.

Error: One or more required fields were not set on the message, please check the documentation on how to set the following message fields: api_key, type, user_id, time_stamp, platform, message at RequiredKeysNotSet

I have set all the required fields but it still throwing an error. Tried for both single and multiple messages. Attached the sample code here.

I am using the following chatbase dependency
@google/chatbase": "^1.1.1"

@parimalyeole
Copy link

parimalyeole commented Jun 18, 2018

I was facing the same issue

Make sure you are passing api_key, type, user_id, time_stamp(not require/ if you pass send in required format), platform in required data type

Fallowing code work for me
` const msg = chatbase.newMessage(API_KEY_CHATBASE, attributes.user.userId)
.setAsTypeAgent()
.setTimestamp(Date.now().toString())
.setPlatform('Alexa')
.setMessage("some msg here")
.setIntent("someintend")
.setCustomSessionId(event.session.sessionId);

msg.send();`

@cristiancavalli
Copy link
Contributor

cristiancavalli commented Jun 18, 2018

@parimalyeole Please make sure that, when setting the timestamp field, it is of type number not string so: .setTimestamp(Date.now()) without the toString() invocation.

@parimalyeole
Copy link

parimalyeole commented Jun 18, 2018

@cristiancavalli
Are you sure about that coz
.setTimestamp(Date.now().toString()) completely work for me....

same is also mention in the documentation of "chatbase-node"
here is implementation...
https://github.com/google/chatbase-node/blob/master/lib/MessageSink.js#L252
https://github.com/google/chatbase-node/blob/master/lib/MessageSink.js#L126

but when we look at the chatbase documentation
https://www.chatbase.com/documentation/generic
it is mention as int
time_stamp: int, <required> milliseconds since the UNIX epoch, used to sequence

I don't know how that is working...

@cristiancavalli
Copy link
Contributor

@parimalyeole you 100% correct, please leave the timestamp code as it. There is a bug which will prevent you from using it the other way I intended which I will post a patch for soon. I was able to get your snippet working though so perhaps the a variable you are supplying to the newMessage function is empty or not of type string? (both api-key and userid must be strings):

 chatbase.newMessage('an-api-key', '123')
    .setPlatform('INTERWEBZ')
    .setMessage('test')
    .setVersion('1.0')
    .setIntent('test-me')
    .setAsTypeAgent()
    .setTimestamp(Date.now().toString())
    .send()
    .then(msg => console.log(msg.getCreateResponse()))
    .catch(err => console.error(err));

please lmk if this does not work for you

@cristiancavalli
Copy link
Contributor

@parimalyeole I think I identified and fixed the issue: due to an api change the field custom_session_id has been supplanted by session_id for providing custom session values. This has been fixed and tests added in commit: ea64b09

@cristiancavalli
Copy link
Contributor

@parimalyeole this has now been updated in version 1.1.2: https://www.npmjs.com/package/@google/chatbase

Thank you for your patience and raising this issue!

@parimalyeole
Copy link

@cristiancavalli, Thanks!!!

@Atitkumar
Copy link

i made a chatbot for room reservation and if i give the old date like 20/2/2010 it is not showing error that this date is already gone i want a solution for this pls help me how do i do that it will show error or not accept the out dated year or month..

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

No branches or pull requests

4 participants