Skip to content

Commit af08cb5

Browse files
authored
Merge pull request #366 from watson-developer-cloud/6668-assistant-v2-examples
Add Assistant V2 examples
2 parents a8ec320 + 5522416 commit af08cb5

File tree

48 files changed

+139
-5120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+139
-5120
lines changed

IBM.Watson.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.Watson.NaturalLanguageU
9595
EndProject
9696
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.Watson.ToneAnalyzer.v3.UnitTests", "test\ToneAnalyzer.v3.UnitTests\IBM.Watson.ToneAnalyzer.v3.UnitTests.csproj", "{28F5A68C-CF5B-4691-A5E5-9135C99470A0}"
9797
EndProject
98+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.Watson.Assistant.v2.Examples", "examples\IBM.Watson.Assistant.v2.Examples\IBM.Watson.Assistant.v2.Examples.csproj", "{4CFF70FE-F96E-46EE-B7FC-E06AEE4EE2AC}"
99+
EndProject
98100
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.Watson.Assistant.v1.Examples", "examples\IBM.Watson.Assistant.v1.Examples\IBM.Watson.Assistant.v1.Examples.csproj", "{AE7F758A-A6FA-49E7-AD3C-52B784BEBA3F}"
99101
EndProject
100102
Global
@@ -235,6 +237,10 @@ Global
235237
{28F5A68C-CF5B-4691-A5E5-9135C99470A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
236238
{28F5A68C-CF5B-4691-A5E5-9135C99470A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
237239
{28F5A68C-CF5B-4691-A5E5-9135C99470A0}.Release|Any CPU.Build.0 = Release|Any CPU
240+
{4CFF70FE-F96E-46EE-B7FC-E06AEE4EE2AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
241+
{4CFF70FE-F96E-46EE-B7FC-E06AEE4EE2AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
242+
{4CFF70FE-F96E-46EE-B7FC-E06AEE4EE2AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
243+
{4CFF70FE-F96E-46EE-B7FC-E06AEE4EE2AC}.Release|Any CPU.Build.0 = Release|Any CPU
238244
{AE7F758A-A6FA-49E7-AD3C-52B784BEBA3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
239245
{AE7F758A-A6FA-49E7-AD3C-52B784BEBA3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
240246
{AE7F758A-A6FA-49E7-AD3C-52B784BEBA3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -276,6 +282,7 @@ Global
276282
{57C7F28F-822A-4C52-909A-F9DB6A0CFA51} = {65D78D49-E54F-4952-A1D4-7C8D0EDAA1B3}
277283
{415AADD4-CC05-4B77-8E57-C1B079421875} = {89D715BF-7464-45FB-8DA0-9D7B46AB8C7F}
278284
{28F5A68C-CF5B-4691-A5E5-9135C99470A0} = {C7873F44-7188-49BE-84C5-532BE4E07147}
285+
{4CFF70FE-F96E-46EE-B7FC-E06AEE4EE2AC} = {90E09BF8-A647-43B8-B721-05CAECFADD72}
279286
{AE7F758A-A6FA-49E7-AD3C-52B784BEBA3F} = {E3D238D7-7A09-4447-B836-8D6ABF4BFF80}
280287
EndGlobalSection
281288
GlobalSection(ExtensibilityGlobals) = postSolution

examples/IBM.Watson.Assistant.v2.Example/AssistantServiceExample.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.

examples/IBM.Watson.Assistant.v2.Example/Example.cs

Lines changed: 0 additions & 79 deletions
This file was deleted.

examples/IBM.Watson.Assistant.v2.Example/IBM.Watson.Assistant.v2.Example.csproj

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="IBM.Cloud.SDK.Core" Version="0.7.1" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\IBM.Watson.Assistant.v2\IBM.Watson.Assistant.v2.csproj" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* Copyright 2019 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
19+
using IBM.Cloud.SDK.Core.Util;
20+
using IBM.Watson.Assistant.v2.Model;
21+
using System;
22+
23+
namespace IBM.Watson.Assistant.v2.Examples
24+
{
25+
class ServiceExample
26+
{
27+
string apikey = "{apikey}";
28+
string url = "{url}";
29+
string versionDate = "{versionDate}";
30+
string assistantId = "{assistantId}";
31+
string sessionId;
32+
string inputString = "hello";
33+
34+
static void Main(string[] args)
35+
{
36+
ServiceExample example = new ServiceExample();
37+
38+
example.CreateSession();
39+
example.Message();
40+
example.DeleteSession();
41+
42+
Console.WriteLine("Examples complete. Press any key to close the application.");
43+
Console.ReadKey();
44+
}
45+
46+
#region Sessions
47+
public void CreateSession()
48+
{
49+
TokenOptions tokenOptions = new TokenOptions()
50+
{
51+
IamApiKey = apikey,
52+
ServiceUrl = url
53+
};
54+
55+
AssistantService service = new AssistantService(tokenOptions, versionDate);
56+
57+
var result = service.CreateSession(
58+
assistantId: assistantId
59+
);
60+
sessionId = result.Result.SessionId;
61+
62+
Console.WriteLine(result.Response);
63+
}
64+
65+
public void DeleteSession()
66+
{
67+
TokenOptions tokenOptions = new TokenOptions()
68+
{
69+
IamApiKey = apikey,
70+
ServiceUrl = url
71+
};
72+
73+
AssistantService service = new AssistantService(tokenOptions, versionDate);
74+
75+
var result = service.DeleteSession(
76+
assistantId: assistantId,
77+
sessionId: sessionId
78+
);
79+
80+
Console.WriteLine(result.Response);
81+
}
82+
#endregion
83+
84+
#region Message
85+
public void Message()
86+
{
87+
TokenOptions tokenOptions = new TokenOptions()
88+
{
89+
IamApiKey = apikey,
90+
ServiceUrl = url
91+
};
92+
93+
AssistantService service = new AssistantService(tokenOptions, versionDate);
94+
95+
MessageInput input = new MessageInput()
96+
{
97+
MessageType = MessageInput.MessageTypeEnumValue.TEXT,
98+
Text = inputString,
99+
Options = new MessageInputOptions()
100+
{
101+
ReturnContext = true,
102+
AlternateIntents = true
103+
}
104+
};
105+
106+
var result = service.Message(
107+
assistantId: assistantId,
108+
sessionId: sessionId,
109+
input: input
110+
);
111+
112+
Console.WriteLine(result.Response);
113+
}
114+
#endregion
115+
}
116+
}

0 commit comments

Comments
 (0)