2

I could avoid writing an API to add new content to a facts template capsule in Bixby if I could simply download a replacement or parallel "content.js" file into the code/ directory. Is there a way to do this in the subset of JavaScript that runs in the Bixby VM? I just want something like:

get url-to-json local-file-target-path

Lazy man's API!?

Fred Zimmerman
  • 1,178
  • 3
  • 13
  • 29
  • The way I understood your question is that you are trying to download a javascript file dynamically into the capsule. If that is correct, then the answer is that it is not possible. You cannot change the capsule file structure once you have made a Submission. – BixbyDevSupportOne Nov 20 '19 at 18:29

2 Answers2

0

You cannot change the file directly one submitted but you can use local javascript file to manually save json data (Like Down Below). Or you can use your Google’s APIs to fetch the the data from google drive files. Such that you can just update file in your google drive and the data will be updated. But Google APIs have certain limits for APIs calls for free use.

At first I assumed you want to save the file locally in the package itself . So I wrote the solution below:

So in order for you to update JSON Locally, you need use require(%code-folder-file-path%) in javascript code. And In you data saving javascript file, use module.exports function to send the data torequire(%code-folder-file-path%) function when it is called from another file.

For Example:

Assume the hierarchy:

-asset
- code
    |_ lib
    |  |_ DataCollection.js
    |_ engine
       |_ Search_Data_Algorithm.js
- action
- model
- resources

Note: Assume that the top hierarchy are the default Folder created when you create new capsule & by default the local path for Javascript Files starts at a root folder called “Code” which in this case contains “lib”, and “engine” as the sub-folders. So the initial top hierarchy folders such as “asset,code,action,model,resources” are the root folder for using the local file paths when calling for the files and folders contained within them.

  1. DataCollection.js
module.exports = JSON.parse(myJSON_data);
myJSON_data = “{•••}”;
  1. Search_Data_Algorithm.js
const Data = require(‘lib/DataCollection.js’);

/** since the root folder is “Code”,
*   we don’t need to write:
*   require(‘code/lib/DataCollection.js’)
*/

console.log(Data); 
// this will output data in JSON file. 

Also Note : if you want to use files from a folder one notch up in hierarchy use ../ in front of the path line and the file/folder name after it.

0

The direct answer is no, you won't be able to do updates like what you described.

However, for dynamic content, you can leverage the capsule config system - https://bixbydevelopers.com/dev/docs/reference/ref-topics/capsule-config

For example, you define a few facts in the capsule configuration properties...

How to configure config And in your code, load them dynamically

var config = require("config")
var myFact01 = config.get('myFact01');
var myFact02 = config.get('myFact02');
var myFact03 = config.get('myFact03');
dogethis
  • 519
  • 6
  • 15