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

docs on using JS interface #205

Closed
dcsan opened this issue Jan 24, 2017 · 5 comments
Closed

docs on using JS interface #205

dcsan opened this issue Jan 24, 2017 · 5 comments

Comments

@dcsan
Copy link
Contributor

dcsan commented Jan 24, 2017

I was trying to get at some variables from a JS Object macro and can't seem to find any docs.

basically I used

   let uservars = rs.getUservars();
console.log("uservars", uservars)

but this seems to give a hash using the userID:

uservars { 
  o_IxAuE6Tz2pZMQM95_6buvQLWKY: 
     { topic: 'dev-intro',
       trigger: 'start',
     __initialmatch__: 'start',
     __history__: { input: [Object], reply: [Object] },
     subscribe: 1,
     openid: 'o_IxAuE6Tz2pZMQM95_6buvQLWKY',
     nickname: 'DC | Rikai Labs',
     sex: 1,
     language: 'en',
     city: '',
     province: '',
     country: '中国',
     subscribe_time: 1484794957,
     remark: '',
     groupid: 0,
     tagid_list: [],
     __lastmatch__: 'start',
     hintcount: 31,
     usercolor: 'blue' } }

is this correct? The JS object doesn't just have the uservars directly accessible I would need to find it off the userID hash? that seems odd.
Then, I'm sure there was a method for getUserId() but I can't seem to find that either in the docs.

https://www.rivescript.com/docs/tutorial#object-macros
http://rivescript.readthedocs.io/en/latest/rivescript.html
https://github.com/aichaos/rivescript-js/tree/master/eg/reply-async

@kirsle
Copy link
Member

kirsle commented Jan 24, 2017

The one you're looking for is rs.currentUser()

rs.getUservars() with no argument returns the hash of all users + all their vars; by passing a specific username, rs.getUservars(rs.currentUser()) it returns a hash of just that user's variables at the top level.

@dcsan
Copy link
Contributor Author

dcsan commented Jan 25, 2017

great, thanks! Are these documented anywhere? otherwise would it help if I made a PR for the wiki?

@dcsan
Copy link
Contributor Author

dcsan commented Jan 25, 2017

@kirsle
Copy link
Member

kirsle commented Jan 25, 2017

getUservars() and currentUser() are documented, but perhaps they could document more info on what the returned structure looks like.

@dcsan
Copy link
Contributor Author

dcsan commented Jan 26, 2017

thanks, noted, updated wiki entry. closing.

@dcsan dcsan closed this as completed Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants