Skip to content

Commit be9f955

Browse files
committed
update readme, fix return type of message
1 parent 2ef8c7e commit be9f955

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

Examples/ServiceExamples/Scripts/ExampleCustomHeaders.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void Start()
133133
#endregion
134134
}
135135

136-
private void OnMessage(MessageResponse response, Dictionary<string, object> customData)
136+
private void OnMessage(object response, Dictionary<string, object> customData)
137137
{
138138
Log.Debug("ExampleCustomHeader.OnMessage()", "Response: {0}", customData["json"].ToString());
139139

README.md

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ To get started with the Watson Services in Unity, click on each service below to
7676
Before you can use a service, it must be authenticated with the service instance's `username`, `password` and `url`.
7777

7878
```cs
79-
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
79+
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
8080
using IBM.Watson.DeveloperCloud.Utilities;
8181

8282
void Start()
8383
{
8484
Credentials credentials = new Credentials(<username>, <password>, <url>);
85-
Conversation _conversation = new Conversation(credentials);
85+
Assistant _assistant = new Assistant(credentials);
8686
}
8787
```
8888

@@ -105,7 +105,7 @@ Success and failure callbacks are required. You can specify the return type in t
105105
private void Example()
106106
{
107107
// Call with sepcific callbacks
108-
conversation.Message(OnMessage, OnGetEnvironmentsFail, _workspaceId, "");
108+
assistant.Message(OnMessage, OnGetEnvironmentsFail, _workspaceId, "");
109109
discovery.GetEnvironments(OnGetEnvironments, OnFail);
110110
}
111111

@@ -139,7 +139,7 @@ Since the success callback signature is generic and the failure callback always
139139
private void Example()
140140
{
141141
// Call with generic callbacks
142-
conversation.Message(OnSuccess, OnMessageFail, "<workspace-id>", "");
142+
assistant.Message(OnSuccess, OnMessageFail, "<workspace-id>", "");
143143
discovery.GetEnvironments(OnSuccess, OnFail);
144144
}
145145

@@ -164,7 +164,7 @@ void Example()
164164
{
165165
Dictionary<string, object> customData = new Dictionary<string, object>();
166166
customData.Add("foo", "bar");
167-
conversation.Message(OnSuccess, OnFail, "<workspace-id>", "", customData);
167+
assistant.Message(OnSuccess, OnFail, "<workspace-id>", "", customData);
168168
}
169169

170170
// Generic success callback
@@ -181,13 +181,54 @@ private void OnFail(RESTConnector.Error error, Dictionary<string, object> custom
181181
}
182182
```
183183

184+
## Custom Request Headers
185+
You can send custom request headers by adding them to the `customData` object.
186+
187+
```cs
188+
void Example()
189+
{
190+
// Create customData object
191+
Dictionary<string, object> customData = new Dictionary<string, object>();
192+
// Create a dictionary of custom headers
193+
Dictionary<string, string> customHeaders = new Dictionary<string, string>();
194+
// Add to the header dictionary
195+
customHeaders.Add("X-Watson-Metadata", "customer_id=some-assistant-customer-id");
196+
// Add the header dictionary to the custom data object
197+
customData.Add(Constants.String.CUSTOM_REQUEST_HEADERS, customHeaders);
198+
199+
assistant.Message(OnSuccess, OnFail, "<workspace-id>", customData: customData);
200+
}
201+
```
202+
203+
## Response Headers
204+
You can get responseheaders in the `customData` object in the callback.
205+
206+
```cs
207+
void Example()
208+
{
209+
assistant.Message(OnMessage, OnFail, "<workspace-id>");
210+
}
211+
212+
private void OnMessage(object resp, Dictionary<string, object> customData)
213+
{
214+
// List all headers in the response headers object
215+
if (customData.ContainsKey(Constants.String.RESPONSE_HEADERS))
216+
{
217+
foreach (KeyValuePair<string, string> kvp in customData[Constants.String.RESPONSE_HEADERS] as Dictionary<string, string>)
218+
{
219+
Log.Debug("ExampleCustomHeader.OnMessage()", "{0}: {1}", kvp.Key, kvp.Value);
220+
}
221+
}
222+
}
223+
```
224+
184225
## Authentication Tokens
185226
You use tokens to write applications that make authenticated requests to IBM Watson™ services without embedding service credentials in every call.
186227

187228
You can write an authentication proxy in IBM Cloud that obtains and returns a token to your client application, which can then use the token to call the service directly. This proxy eliminates the need to channel all service requests through an intermediate server-side application, which is otherwise necessary to avoid exposing your service credentials from your client application.
188229

189230
```cs
190-
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
231+
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
191232
using IBM.Watson.DeveloperCloud.Utilities;
192233

193234
void Start()
@@ -196,7 +237,7 @@ void Start()
196237
{
197238
AuthenticationToken = <authentication-token>
198239
};
199-
Conversation _conversation = new Conversation(credentials);
240+
Assistant _assistant = new Assistant(credentials);
200241
}
201242
```
202243

0 commit comments

Comments
 (0)