forked from watson-developer-cloud/unity-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleAssistantV1.cs
More file actions
681 lines (596 loc) · 31.4 KB
/
ExampleAssistantV1.cs
File metadata and controls
681 lines (596 loc) · 31.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/**
* Copyright 2019 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using IBM.Watson.Assistant.V1;
using IBM.Cloud.SDK;
using IBM.Cloud.SDK.Authentication;
using IBM.Cloud.SDK.Authentication.Iam;
using IBM.Cloud.SDK.Utilities;
using IBM.Watson.Assistant.V1.Model;
using System;
namespace IBM.Watson.Examples
{
public class ExampleAssistantV1 : MonoBehaviour
{
private AssistantService service;
private string workspaceId;
private string createdWorkspaceId;
private string inputString = "Hello";
private string conversationString0 = "unlock the door";
private string conversationString1 = "turn on the ac";
private string conversationString2 = "turn down the radio";
private static string createdWorkspaceName = "unity-sdk-example-workspace-delete";
private static string createdWorkspaceDescription = "A Workspace created by the Unity SDK Assistant example script. Please delete this.";
private static string createdWorkspaceLanguage = "en";
private static string createdEntity = "unityEntity";
private static string createdEntityDescription = "Entity created by the Unity SDK Assistant example script.";
private static string createdValue = "unityunityalue";
private static string createdIntent = "unityIntent";
private static string createdIntentDescription = "Intent created by the Unity SDK Assistant example script.";
private static string createdCounterExampleText = "unityExample text";
private static string createdSynonym = "unitySynonym";
private static string createdExample = "unityExample";
private static string dialogNodeName = "unityDialognode";
private static string dialogNodeDesc = "Unity SDK Integration test dialog node";
private Dictionary<string, object> context = null;
private bool listWorkspacesTested = false;
private bool createWorkspaceTested = false;
private bool getWorkspaceTested = false;
private bool updateWorkspaceTested = false;
private bool messageTested = false;
private bool listIntentsTested = false;
private bool createIntentTested = false;
private bool getIntentTested = false;
private bool updateIntentTested = false;
private bool listExamplesTested = false;
private bool createExampleTested = false;
private bool getExampleTested = false;
private bool updateExampleTested = false;
private bool listEntitiesTested = false;
private bool createEntityTested = false;
private bool getEntityTested = false;
private bool updateEntityTested = false;
private bool listMentionsTested = false;
private bool listValuesTested = false;
private bool createValueTested = false;
private bool getValueTested = false;
private bool updateValueTested = false;
private bool listSynonymsTested = false;
private bool createSynonymTested = false;
private bool getSynonymTested = false;
private bool updateSynonymTested = false;
private bool listDialogNodesTested = false;
private bool createDialogNodeTested = false;
private bool getDialogNodeTested = false;
private bool updateDialogNodeTested = false;
private bool listLogsInWorkspaceTested = false;
private bool listAllLogsTested = false;
private bool listCounterexamplesTested = false;
private bool createCounterexampleTested = false;
private bool getCounterexampleTested = false;
private bool updateCounterexampleTested = false;
private bool deleteCounterexampleTested = false;
private bool deleteDialogNodeTested = false;
private bool deleteSynonymTested = false;
private bool deleteValueTested = false;
private bool deleteEntityTested = false;
private bool deleteExampleTested = false;
private bool deleteIntentTested = false;
private bool deleteWorkspaceTested = false;
private void Start()
{
LogSystem.InstallDefaultReactors();
Runnable.Run(CreateService());
}
private IEnumerator CreateService()
{
IamAuthenticator authenticator = new IamAuthenticator(apikey: "{iamApikey}");
// Wait for tokendata
while (!authenticator.CanAuthenticate())
yield return null;
service = new AssistantService("2019-02-18", authenticator);
service.SetServiceUrl("{serviceUrl}");
workspaceId = Environment.GetEnvironmentVariable("CONVERSATION_WORKSPACE_ID");
Runnable.Run(Examples());
}
private IEnumerator Examples()
{
// List Workspaces
Log.Debug("ExampleAssistantV1", "Attempting to ListWorkspaces...");
service.ListWorkspaces(callback: OnListWorkspaces, pageLimit: 1, sort: "-name", includeAudit: true);
while (!listWorkspacesTested)
yield return null;
Log.Debug("ExampleAssistantV1", "Attempting to CreateWorkspace...");
service.CreateWorkspace(callback: OnCreateWorkspace, name: createdWorkspaceName, description: createdWorkspaceDescription, language: createdWorkspaceLanguage, learningOptOut: true);
while (!createWorkspaceTested)
yield return null;
// Get Workspace
Log.Debug("ExampleAssistantV1", "Attempting to GetWorkspace...");
service.GetWorkspace(callback: OnGetWorkspace, workspaceId: createdWorkspaceId);
while (!getWorkspaceTested)
yield return null;
Log.Debug("ExampleAssistantV1", "Attempting to UpdateWorkspace...");
service.UpdateWorkspace(callback: OnUpdateWorkspace, workspaceId: createdWorkspaceId, name: createdWorkspaceName + "Updated", description: createdWorkspaceDescription + "Updated", language: createdWorkspaceLanguage);
while (!updateWorkspaceTested)
yield return null;
// Message
Dictionary<string, object> input = new Dictionary<string, object>();
input.Add("text", inputString);
//InputData input = new InputData()
//{
// Text = inputString
//};
//Log.Debug("ExampleAssistantV1", "Attempting to Message...");
//service.Message(callback: OnMessage, workspaceId: workspaceId, input: input);
//while (!messageTested)
// yield return null;
//messageTested = false;
//input = new InputData()
//{
// Text = conversationString0
//};
//Log.Debug("ExampleAssistantV1", "Attempting to Message...");
//service.Message(callback: OnMessage, workspaceId: workspaceId, input: input, context: context);
//while (!messageTested)
// yield return null;
//messageTested = false;
//input = new InputData()
//{
// Text = conversationString1
//};
//Log.Debug("ExampleAssistantV1", "Attempting to Message...");
//service.Message(callback: OnMessage, workspaceId: workspaceId, input: input, context: context);
//while (!messageTested)
// yield return null;
//messageTested = false;
//input = new InputData()
//{
// Text = conversationString2
//};
//Log.Debug("ExampleAssistantV1", "Attempting to Message...");
//service.Message(callback: OnMessage, workspaceId: workspaceId, input: input, context: context);
//while (!messageTested)
// yield return null;
// List Intents
Log.Debug("ExampleAssistantV1", "Attempting to ListIntents...");
service.ListIntents(callback: OnListIntents, workspaceId: createdWorkspaceId);
while (!listIntentsTested)
yield return null;
//// Create Intent
Log.Debug("ExampleAssistantV1", "Attempting to CreateIntent...");
service.CreateIntent(callback: OnCreateIntent, workspaceId: createdWorkspaceId, intent: createdIntent, description: createdIntentDescription);
while (!createIntentTested)
yield return null;
// Get Intent
service.GetIntent(callback: OnGetIntent, workspaceId: createdWorkspaceId, intent: createdIntent);
while (!getIntentTested)
yield return null;
// Update Intents
string updatedIntent = createdIntent + "Updated";
string updatedIntentDescription = createdIntentDescription + "Updated";
service.UpdateIntent(callback: OnUpdateIntent, workspaceId: createdWorkspaceId, intent: createdIntent, newIntent: updatedIntent, newDescription: updatedIntentDescription);
while (!updateIntentTested)
yield return null;
// List Examples
service.ListExamples(callback: OnListExamples, workspaceId: createdWorkspaceId, intent: updatedIntent);
while (!listExamplesTested)
yield return null;
// Create Examples
service.CreateExample(callback: OnCreateExample, workspaceId: createdWorkspaceId, intent: updatedIntent, text: createdExample);
while (!createExampleTested)
yield return null;
// Get Example
service.GetExample(callback: OnGetExample, workspaceId: createdWorkspaceId, intent: updatedIntent, text: createdExample);
while (!getExampleTested)
yield return null;
// Update Examples
string updatedExample = createdExample + "Updated";
service.UpdateExample(callback: OnUpdateExample, workspaceId: createdWorkspaceId, intent: updatedIntent, text: createdExample, newText: updatedExample);
while (!updateExampleTested)
yield return null;
// List Entities
service.ListEntities(callback: OnListEntities, workspaceId: createdWorkspaceId);
while (!listEntitiesTested)
yield return null;
// Create Entities
service.CreateEntity(callback: OnCreateEntity, workspaceId: createdWorkspaceId, entity: createdEntity, description: createdEntityDescription);
while (!createEntityTested)
yield return null;
// Get Entity
service.GetEntity(callback: OnGetEntity, workspaceId: createdWorkspaceId, entity: createdEntity);
while (!getEntityTested)
yield return null;
// Update Entities
string updatedEntity = createdEntity + "Updated";
string updatedEntityDescription = createdEntityDescription + "Updated";
service.UpdateEntity(callback: OnUpdateEntity, workspaceId: createdWorkspaceId, entity: createdEntity, newEntity: updatedEntity, newDescription: updatedEntityDescription);
while (!updateEntityTested)
yield return null;
// List Mentinos
service.ListMentions(callback: OnListMentions, workspaceId: createdWorkspaceId, entity: updatedEntity);
while (!listMentionsTested)
yield return null;
// List Values
service.ListValues(callback: OnListValues, workspaceId: createdWorkspaceId, entity: updatedEntity);
while (!listValuesTested)
yield return null;
// Create Values
service.CreateValue(callback: OnCreateValue, workspaceId: createdWorkspaceId, entity: updatedEntity, value: createdValue);
while (!createValueTested)
yield return null;
// Get Value
service.GetValue(callback: OnGetValue, workspaceId: createdWorkspaceId, entity: updatedEntity, value: createdValue);
while (!getValueTested)
yield return null;
// Update Values
string updatedValue = createdValue + "Updated";
service.UpdateValue(callback: OnUpdateValue, workspaceId: createdWorkspaceId, entity: updatedEntity, value: createdValue, newValue: updatedValue);
while (!updateValueTested)
yield return null;
// List Synonyms
service.ListSynonyms(callback: OnListSynonyms, workspaceId: createdWorkspaceId, entity: updatedEntity, value: updatedValue);
while (!listSynonymsTested)
yield return null;
// Create Synonyms
service.CreateSynonym(callback: OnCreateSynonym, workspaceId: createdWorkspaceId, entity: updatedEntity, value: updatedValue, synonym: createdSynonym);
while (!createSynonymTested)
yield return null;
// Get Synonym
service.GetSynonym(callback: OnGetSynonym, workspaceId: createdWorkspaceId, entity: updatedEntity, value: updatedValue, synonym: createdSynonym);
while (!getSynonymTested)
yield return null;
// Update Synonyms
string updatedSynonym = createdSynonym + "Updated";
service.UpdateSynonym(callback: OnUpdateSynonym, workspaceId: createdWorkspaceId, entity: updatedEntity, value: updatedValue, synonym: createdSynonym, newSynonym: updatedSynonym);
while (!updateSynonymTested)
yield return null;
// List Dialog Nodes
service.ListDialogNodes(callback: OnListDialogNodes, workspaceId: createdWorkspaceId);
while (!listDialogNodesTested)
yield return null;
// Create Dialog Nodes
service.CreateDialogNode(callback: OnCreateDialogNode, workspaceId: createdWorkspaceId, dialogNode: dialogNodeName, description: dialogNodeDesc);
while (!createDialogNodeTested)
yield return null;
// Get Dialog Node
service.GetDialogNode(callback: OnGetDialogNode, workspaceId: createdWorkspaceId, dialogNode: dialogNodeName);
while (!getDialogNodeTested)
yield return null;
// Update Dialog Nodes
string updatedDialogNodeName = dialogNodeName + "Updated";
string updatedDialogNodeDescription = dialogNodeDesc + "Updated";
service.UpdateDialogNode(callback: OnUpdateDialogNode, workspaceId: createdWorkspaceId, dialogNode: dialogNodeName, newDialogNode: updatedDialogNodeName, newDescription: updatedDialogNodeDescription);
while (!updateDialogNodeTested)
yield return null;
// List Logs In Workspace
service.ListLogs(callback: OnListLogs, workspaceId: createdWorkspaceId);
while (!listLogsInWorkspaceTested)
yield return null;
// List All Logs
var filter = "(language::en,request.context.metadata.deployment::deployment_1)";
service.ListAllLogs(callback: OnListAllLogs, filter: filter);
while (!listAllLogsTested)
yield return null;
// List Counterexamples
service.ListCounterexamples(callback: OnListCounterexamples, workspaceId: createdWorkspaceId);
while (!listCounterexamplesTested)
yield return null;
// Create Counterexamples
service.CreateCounterexample(callback: OnCreateCounterexample, workspaceId: createdWorkspaceId, text: createdCounterExampleText);
while (!createCounterexampleTested)
yield return null;
// Get Counterexample
service.GetCounterexample(callback: OnGetCounterexample, workspaceId: createdWorkspaceId, text: createdCounterExampleText);
while (!getCounterexampleTested)
yield return null;
// Update Counterexamples
string updatedCounterExampleText = createdCounterExampleText + "Updated";
service.UpdateCounterexample(callback: OnUpdateCounterexample, workspaceId: createdWorkspaceId, text: createdCounterExampleText, newText: updatedCounterExampleText);
while (!updateCounterexampleTested)
yield return null;
// Delete Counterexample
service.DeleteCounterexample(callback: OnDeleteCounterexample, workspaceId: createdWorkspaceId, text: updatedCounterExampleText);
while (!deleteCounterexampleTested)
yield return null;
// Delete Dialog Node
service.DeleteDialogNode(callback: OnDeleteDialogNode, workspaceId: createdWorkspaceId, dialogNode: updatedDialogNodeName);
while (!deleteDialogNodeTested)
yield return null;
// Delete Synonym
service.DeleteSynonym(callback: OnDeleteSynonym, workspaceId: createdWorkspaceId, entity: updatedEntity, value: updatedValue, synonym: updatedSynonym);
while (!deleteSynonymTested)
yield return null;
// Delete Value
service.DeleteValue(callback: OnDeleteValue, workspaceId: createdWorkspaceId, entity: updatedEntity, value: updatedValue);
while (!deleteValueTested)
yield return null;
// Delete Entity
service.DeleteEntity(callback: OnDeleteEntity, workspaceId: createdWorkspaceId, entity: updatedEntity);
while (!deleteEntityTested)
yield return null;
// Delete Example
service.DeleteExample(callback: OnDeleteExample, workspaceId: createdWorkspaceId, intent: updatedIntent, text: updatedExample);
while (!deleteExampleTested)
yield return null;
// Delete Intent
service.DeleteIntent(callback: OnDeleteIntent, workspaceId: createdWorkspaceId, intent: updatedIntent);
while (!deleteIntentTested)
yield return null;
// Delete Workspace
service.DeleteWorkspace(callback: OnDeleteWorkspace, workspaceId: createdWorkspaceId);
while (!deleteWorkspaceTested)
yield return null;
Log.Debug("ExampleAssistantV1.RunTest()", "Assistant examples complete.");
yield break;
}
private void OnListMentions(DetailedResponse<EntityMentionCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListMentions()", "Response: {0}", response.Response);
listMentionsTested = true;
}
private void OnDeleteWorkspace(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteWorkspace()", "Response: {0}", response.Response);
deleteWorkspaceTested = true;
}
private void OnDeleteIntent(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteIntent()", "Response: {0}", response.Response);
deleteIntentTested = true;
}
private void OnDeleteExample(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteExample()", "Response: {0}", response.Response);
deleteExampleTested = true;
}
private void OnDeleteEntity(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteEntity()", "Response: {0}", response.Response);
deleteEntityTested = true;
}
private void OnDeleteValue(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteValue()", "Response: {0}", response.Response);
deleteValueTested = true;
}
private void OnDeleteSynonym(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteSynonym()", "Response: {0}", response.Response);
deleteSynonymTested = true;
}
private void OnDeleteDialogNode(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteDialogNode()", "Response: {0}", response.Response);
deleteDialogNodeTested = true;
}
private void OnDeleteCounterexample(DetailedResponse<object> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnDeleteCounterexample()", "Response: {0}", response.Response);
deleteCounterexampleTested = true;
}
private void OnUpdateCounterexample(DetailedResponse<Counterexample> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateCounterexample()", "Response: {0}", response.Response);
updateCounterexampleTested = true;
}
private void OnGetCounterexample(DetailedResponse<Counterexample> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetCounterexample()", "Response: {0}", response.Response);
getCounterexampleTested = true;
}
private void OnCreateCounterexample(DetailedResponse<Counterexample> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateCounterexample()", "Response: {0}", response.Response);
createCounterexampleTested = true;
}
private void OnListCounterexamples(DetailedResponse<CounterexampleCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListCounterexamples()", "Response: {0}", response.Response);
listCounterexamplesTested = true;
}
private void OnListAllLogs(DetailedResponse<LogCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListAllLogs()", "Response: {0}", response.Response);
listAllLogsTested = true;
}
private void OnListLogs(DetailedResponse<LogCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListLogs()", "Response: {0}", response.Response);
listLogsInWorkspaceTested = true;
}
private void OnUpdateDialogNode(DetailedResponse<DialogNode> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateDialogNode()", "Response: {0}", response.Response);
updateDialogNodeTested = true;
}
private void OnGetDialogNode(DetailedResponse<DialogNode> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetDialogNode()", "Response: {0}", response.Response);
getDialogNodeTested = true;
}
private void OnCreateDialogNode(DetailedResponse<DialogNode> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateDialogNode()", "Response: {0}", response.Response);
createDialogNodeTested = true;
}
private void OnListDialogNodes(DetailedResponse<DialogNodeCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListDialogNodes()", "Response: {0}", response.Response);
listDialogNodesTested = true;
}
private void OnUpdateSynonym(DetailedResponse<Synonym> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateSynonym()", "Response: {0}", response.Response);
updateSynonymTested = true;
}
private void OnGetSynonym(DetailedResponse<Synonym> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetSynonym()", "Response: {0}", response.Response);
getSynonymTested = true;
}
private void OnCreateSynonym(DetailedResponse<Synonym> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateSynonym()", "Response: {0}", response.Response);
createSynonymTested = true;
}
private void OnListSynonyms(DetailedResponse<SynonymCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListSynonyms()", "Response: {0}", response.Response);
listSynonymsTested = true;
}
private void OnUpdateValue(DetailedResponse<Value> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateValue()", "Response: {0}", response.Response);
updateValueTested = true;
}
private void OnGetValue(DetailedResponse<Value> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetValue()", "Response: {0}", response.Response);
getValueTested = true;
}
private void OnCreateValue(DetailedResponse<Value> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateValue()", "Response: {0}", response.Response);
createValueTested = true;
}
private void OnListValues(DetailedResponse<ValueCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListValues()", "Response: {0}", response.Response);
listValuesTested = true;
}
private void OnUpdateEntity(DetailedResponse<Entity> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateEntity()", "Response: {0}", response.Response);
updateEntityTested = true;
}
private void OnGetEntity(DetailedResponse<Entity> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetEntity()", "Response: {0}", response.Response);
getEntityTested = true;
}
private void OnCreateEntity(DetailedResponse<Entity> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateEntity()", "Response: {0}", response.Response);
createEntityTested = true;
}
private void OnListEntities(DetailedResponse<EntityCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListEntities()", "Response: {0}", response.Response);
listEntitiesTested = true;
}
private void OnUpdateExample(DetailedResponse<Example> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateExample()", "Response: {0}", response.Response);
updateExampleTested = true;
}
private void OnGetExample(DetailedResponse<Example> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetExample()", "Response: {0}", response.Response);
getExampleTested = true;
}
private void OnCreateExample(DetailedResponse<Example> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateExample()", "Response: {0}", response.Response);
createExampleTested = true;
}
private void OnListExamples(DetailedResponse<ExampleCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListExamples()", "Response: {0}", response.Response);
listExamplesTested = true;
}
private void OnUpdateIntent(DetailedResponse<Intent> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateIntent()", "Response: {0}", response.Response);
updateIntentTested = true;
}
private void OnGetIntent(DetailedResponse<Intent> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetIntent()", "Response: {0}", response.Response);
getIntentTested = true;
}
private void OnCreateIntent(DetailedResponse<Intent> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateIntent()", "Response: {0}", response.Response);
createIntentTested = true;
}
private void OnListIntents(DetailedResponse<IntentCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListIntents()", "Response: {0}", response.Response);
listIntentsTested = true;
}
private void OnMessage(DetailedResponse<Dictionary<string, object>> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnMessage()", "Response: {0}", response.Response);
context = response.Result["context"] as Dictionary<string, object>;
//// Convert resp to fsdata
//fsData fsdata = null;
//fsResult r = _serializer.TrySerialize(response.GetType(), response, out fsdata);
//if (!r.Succeeded)
// throw new WatsonException(r.FormattedMessages);
//// Convert fsdata to MessageResponse
//MessageResponse messageResponse = new MessageResponse();
//object obj = messageResponse;
//r = _serializer.TryDeserialize(fsdata, obj.GetType(), ref obj);
//if (!r.Succeeded)
// throw new WatsonException(r.FormattedMessages);
//// Set context for next round of messaging
//object _tempContext = null;
//(response as Dictionary<string, object>).TryGetValue("context", out _tempContext);
//if (_tempContext != null)
// context = _tempContext as Dictionary<string, object>;
//else
// Log.Debug("ExampleAssistantV1.OnMessage()", "Failed to get context");
//// Get intent
//object tempIntentsObj = null;
//(response as Dictionary<string, object>).TryGetValue("intents", out tempIntentsObj);
//object tempIntentObj = (tempIntentsObj as List<object>)[0];
//object tempIntent = null;
//(tempIntentObj as Dictionary<string, object>).TryGetValue("intent", out tempIntent);
//string intent = tempIntent.ToString();
//Log.Debug("ExampleAssistantV1.OnMessage()", "intent: {0}", intent);
messageTested = true;
}
private void OnUpdateWorkspace(DetailedResponse<Workspace> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnUpdateWorkspace()", "Response: {0}", response.Response);
updateWorkspaceTested = true;
}
private void OnGetWorkspace(DetailedResponse<Workspace> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnGetWorkspace()", "Response: {0}", response.Response);
getWorkspaceTested = true;
}
private void OnCreateWorkspace(DetailedResponse<Workspace> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnCreateWorkspace()", "Response: {0}", response.Response);
createdWorkspaceId = response.Result.WorkspaceId;
createWorkspaceTested = true;
}
private void OnListWorkspaces(DetailedResponse<WorkspaceCollection> response, IBMError error)
{
Log.Debug("ExampleAssistantV1.OnListWorkspaces()", "Response: {0}", response.Response);
foreach (Workspace workspace in response.Result.Workspaces)
{
if (workspace.Name.Contains("unity"))
service.DeleteWorkspace(callback: OnDeleteWorkspace, workspaceId: workspace.WorkspaceId);
}
listWorkspacesTested = true;
}
}
}