Skip to content

Instantly share code, notes, and snippets.

@akeller
Created May 15, 2018 14:32
Show Gist options
  • Save akeller/a7f5b41720bab384e7951dadee417e3e to your computer and use it in GitHub Desktop.
Save akeller/a7f5b41720bab384e7951dadee417e3e to your computer and use it in GitHub Desktop.
Initiation Watson Assistant with the Watson Unity SDK
//*******************************************
//You may have initiated Watson Conversation with the Watson Unity SDK previously like this, within the start function with a string.
//*******************************************
void Start()
{
//enter username and password as a string
Credentials credentials = new Credentials(<username>, <password>, "https://gateway.watsonplatform.net/conversation/api");
Conversation _conversation = new Conversation(credentials);
//be sure to give it a Version Date
_conversation.VersionDate = "2017-05-26";
//enter workspace_id as string
if (!_conversation.Message(OnMessage, OnFail, <workspace_id>, "Hi!"))
{
Log.Debug("ExampleConversation.Message()", "Failed to message!");
}
}
//*******************************************
//Now, with Watson Assistant, the Watson Unity SDK abstraction for an Assistant message doesn't take a simple string. You'll need to create an object. This snippet is wrapped in a function I can call, but very similar to the above snippet.
//*******************************************
//Initiate a conversation
private void Message0()
{
inputObj.Add("text", outputText);
MessageRequest messageRequest = new MessageRequest()
{
Input = inputObj
};
if (!_assistant.Message(OnMessage, OnFail, assistantWorkspace, messageRequest))
Log.Debug("ExampleAssistant.Message()", "Failed to message!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment