问题
Is there a way to update my conversation workspace without changing the workspace ID? I need to refresh my stage and prod workspaces every now and then. I use the Import option, but that creates a new workspace with a different workspace ID. This means I need to go and update the same in my app as well. I know I can potentially have it as an external environment variable. But ideally, I would want to avoid that as well. I just want a way to "update" an existing workspace without changing its ID.
回答1:
Check the new Workspace API functionality. It will allow you to update a workspace programmatically without having to import.
I would recommend to test to see how it works before attempting to use it.
回答2:
In the case I know two forms with Examples of IBM Developers. .
1st: have the .env
file, where you can add your WORKSPACE_ID
and you don't need to be adding in the "Environment Variables" inside the Watson Conversation.
Check the .env
example file with this Conversation simple - Nodejs and this Conversation enhanced - Java
Example:
Add the values inside .env
file:
# Environment variables
WORKSPACE_ID=<workspace-id>
CONVERSATION_USERNAME=<conversation-username>
CONVERSATION_PASSWORD=<conversation-password>
2nd: Adding the value of the username
, password
, and workspace_id
variables inside the code.
The password
and the username
in the case is the Service Credentials, inside Conversation Service.
Example:
Add your credentials and workspace_id - Conversation simple (app.js
):
var conversation = new Conversation({
// If unspecified here, the CONVERSATION_USERNAME and CONVERSATION_PASSWORD env properties will be checked
// After that, the SDK will fall back to the bluemix-provided VCAP_SERVICES environment property
// username: '<username>', // add your username here
// password: '<password>', // add your password here
url: 'https://gateway.watsonplatform.net/conversation/api',
version_date: '2016-10-21',
version: 'v1'
});
// Endpoint to be call from the client side
app.post('/api/message', function(req, res) {
var workspace = process.env.WORKSPACE_ID || '<workspace-id>'; //if you dont added the value of workspace_id inside .env file, the app.js will try reconigze the value inside '<workspace-id>'
来源:https://stackoverflow.com/questions/42508848/update-conversation-service-workspace-without-changing-workspace-id