|
15 | 15 | * |
16 | 16 | */ |
17 | 17 |
|
| 18 | +using IBM.Cloud.SDK.Core.Util; |
| 19 | +using IBM.Watson.ToneAnalyzer.v3.Model; |
18 | 20 | using System; |
| 21 | +using System.Collections.Generic; |
19 | 22 |
|
20 | 23 | namespace IBM.Watson.ToneAnalyzer.v3.Examples |
21 | 24 | { |
22 | 25 | public class ServiceExample |
23 | 26 | { |
24 | 27 | string apikey = "{apikey}"; |
25 | 28 | string url = "{url}"; |
26 | | - private string versionDate = "2016-05-19"; |
| 29 | + private string versionDate = "{versionDate}"; |
27 | 30 |
|
28 | 31 | static void Main(string[] args) |
29 | 32 | { |
30 | 33 | ServiceExample example = new ServiceExample(); |
31 | 34 |
|
| 35 | + example.Tone(); |
| 36 | + example.ToneChat(); |
| 37 | + |
32 | 38 | Console.WriteLine("Examples complete. Press any key to close the application."); |
33 | 39 | Console.ReadKey(); |
34 | 40 | } |
| 41 | + |
| 42 | + #region Analyze Tone |
| 43 | + public void Tone() |
| 44 | + { |
| 45 | + TokenOptions tokenOptions = new TokenOptions() |
| 46 | + { |
| 47 | + IamApiKey = apikey, |
| 48 | + ServiceUrl = url |
| 49 | + }; |
| 50 | + |
| 51 | + ToneAnalyzerService service = new ToneAnalyzerService(tokenOptions, versionDate); |
| 52 | + |
| 53 | + ToneInput toneInput = new ToneInput() |
| 54 | + { |
| 55 | + Text = "Hello! Welcome to IBM Watson! How can I help you?" |
| 56 | + }; |
| 57 | + |
| 58 | + var result = service.Tone( |
| 59 | + toneInput: toneInput, |
| 60 | + contentType: "text/html", |
| 61 | + sentences: true, |
| 62 | + contentLanguage: "en-US", |
| 63 | + acceptLanguage: "en-US" |
| 64 | + ); |
| 65 | + |
| 66 | + Console.WriteLine(result.Response); |
| 67 | + } |
| 68 | + #endregion |
| 69 | + |
| 70 | + #region Analyze Customer Engagment Tone |
| 71 | + public void ToneChat() |
| 72 | + { |
| 73 | + TokenOptions tokenOptions = new TokenOptions() |
| 74 | + { |
| 75 | + IamApiKey = apikey, |
| 76 | + ServiceUrl = url |
| 77 | + }; |
| 78 | + |
| 79 | + ToneAnalyzerService service = new ToneAnalyzerService(tokenOptions, versionDate); |
| 80 | + |
| 81 | + var utterances = new List<Utterance>() |
| 82 | + { |
| 83 | + new Utterance() |
| 84 | + { |
| 85 | + Text = "Hello! Welcome to IBM Watson! How can I help you?", |
| 86 | + User = "testChatUser" |
| 87 | + } |
| 88 | + }; |
| 89 | + |
| 90 | + var result = service.ToneChat( |
| 91 | + utterances: utterances, |
| 92 | + contentLanguage: "en-US", |
| 93 | + acceptLanguage: "en-US" |
| 94 | + ); |
| 95 | + |
| 96 | + Console.WriteLine(result.Response); |
| 97 | + } |
| 98 | + #endregion |
35 | 99 | } |
36 | 100 | } |
0 commit comments