1

I am looking to greet a user with his first and last name with my capsule. I looked at this page, which would contain everything I need. I added the capsule-import / permission to do this. But I have not been able to access this user information from inside JavaScript code.

Confirmation.js:

 var config = require('config')
 var http = require('http')
 var console = require('console')

module.exports.function = function getConfirmation ($vivContext, $user) {

  let result = "Hello"

  console.log($user)
  console.log($vivContext)

  return result

}

capsule.bxb

capsule {
  id (fastforward.oauthGoogleTest)
  version (0.1.0)
  format(3)

  store-sections {
    section (Photography)
    section (NewsAndMagazines)
  }

  capsule-categories{
    category (News)
  }

  targets{
    target (bixby-mobile-en-US)
  }

  marketplace-constraints {
    country-constraints {
      allowed-list {
        allow (US)
        allow (KR)
      }
    }
  }

  permissions{
    // bixby-user-id-access
    user-profile-access
  }

  runtime-flags {
    use-input-views-for-selection-list-detail
    modern-default-view-behavior
    concepts-inherit-super-type-features
    modern-prompt-rejection
    support-halt-effect-in-computed-inputs
    no-filtering-with-validation
  }

  capsule-imports {
    import (viv.contact) {
      as (contact)
      version (2.5156.4)
    }
    import (viv.self) { 
      as (profile) 
      version (3.5.167)
    }
  }

}

hello_world.model.bxb

action (hello_world) {
  type (Search)
  description (just a small test for oauth)
  output (confirmation)
}

endpoints.bxb

endpoints {
  action-endpoints {
    action-endpoint (hello_world) {
      local-endpoint (Confirmation.js)
      accepted-inputs ($vivContext, $user)
      authorization: user
    }
  }
}

I would like to access user information is my javascript code, how do I do that?

  • Welcome to [StackOverflow.com](https://www.stackoverflow.com)! Your question is lacking of details: [we are simply unable to help you in its current state...](https://stackoverflow.com/help/how-to-ask) Edit the answer to specify *at least*: What have you tried so far? What technologies/languages are you using? What are you trying to accomplish? What do you get *precisely*? Generally, [avoid just asking for help](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question). – Sterconium Nov 12 '19 at 15:55
  • Can you provide a code snippit of your Javascript code that shows how you are attempting to access the profile information? – JP Alioto Nov 12 '19 at 16:23

2 Answers2

1

These informations are not in $vivContext, please see https://bixbydevelopers.com/dev/docs/dev-guide/developers/actions.js-actions#passing-user-context-information for detailed info on $vivContext.

To extract the info from viv.self, you need to do computed-inputs as the following.

    // self can be computed rather than explicitly passed
    computed-input (self) { 
      type (self.Self) // import viv.self { as (self) }
      min (Optional) max (One)
      compute {
        intent {
          goal: self.Self
          route: self.GetSelf
        }
      }
    }

Learn more about viv.self at https://bixbydevelopers.com/dev/docs/dev-guide/developers/library.self

Please note there is a typo that should import viv.self as (self)

  • Hey, thank for the response, I tried it out but I get an error on `computed-input(self)` saying `ERROR Unresolved input: self:self.Self. I thought the capsule-import would handle that? If I have to add to `collect` an `input` what would it look like? This is not clear from reading the documentation. – Erik Stevens Nov 14 '19 at 08:58
  • in capsule-import, import viv.self as self – BixbyDevSupport-Tokonyan Nov 14 '19 at 18:21
0

Erik, Here is a link to "computed-input" ref doc

I'm trying to do the same thing as you, but haven't managed to get it to work

edit.... I was able to get the computed-input to work and retrieve first & last name as well as email address, but for some reason I can't get mailing address

Faengelm
  • 66
  • 5