• Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🆕🆕🆕.NET Standard library to access Watson Services.

Watson Developer Cloud .NET Standard SDK

Build and Test Deploy and Publish Coverage Status wdc-community.slack.com CLA assistant semantic-release Documentation

Deprecated builds

Build status

The .NET Standard SDK uses Watson services, a collection of REST APIs that use cognitive computing to solve complex problems.

Announcements

Tone Analyzer Deprecation

As of this major release, 6.0.0, the Tone Analyzer API has been removed in preparation for deprecation. If you wish to continue using this sdk to make calls to Tone Analyzer until its final deprecation, you will have to use a previous version. On 24 February 2022, IBM announced the deprecation of the Tone Analyzer service. The service will no longer be available as of 24 February 2023. As of 24 February 2022, you will not be able to create new instances. Existing instances will be supported until 24 February 2023.

As an alternative, we encourage you to consider migrating to the Natural Language Understanding service on IBM Cloud. With Natural Language Understanding, tone analysis is done by using a pre-built classifications model, which provides an easy way to detect language tones in written text. For more information, see Migrating from Watson Tone Analyzer Customer Engagement endpoint to Natural Language Understanding.

Natural Language Classifier Deprecation

As of this major release, 6.0.0, the NLC API has been removed in preparation for deprecation. If you wish to continue using this sdk to make calls to NLC until its final deprecation, you will have to use a previous version. On 9 August 2021, IBM announced the deprecation of the Natural Language Classifier service. The service will no longer be available from 8 August 2022. As of 9 September 2021, you will not be able to create new instances. Existing instances will be supported until 8 August 2022. Any instance that still exists on that date will be deleted.

As an alternative, we encourage you to consider migrating to the Natural Language Understanding service on IBM Cloud that uses deep learning to extract data and insights from text such as keywords, categories, sentiment, emotion, and syntax, along with advanced multi-label text classification capabilities, to provide even richer insights for your business or industry. For more information, see Migrating to Natural Language Understanding.

Updating endpoint URLs from watsonplatform.net

Watson API endpoint URLs at watsonplatform.net are changing and will not work after 26 May 2021. Update your calls to use the newer endpoint URLs. For more information, see https://cloud.ibm.com/docs/watson?topic=watson-endpoint-change.

Before you begin

Ensure you have the following prerequisites:

Installing the Watson .NET Standard SDK

This SDK provides classes and methods to access the following Watson services:

You can get the latest SDK packages through NuGet or manually here.

.NET Standard 2.0

The Watson .NET Standard SDK conforms to .NET Standard 2.0. It is implemented by .NET Core 2.0, .NET Framework 4.6.1 and Mono 5.4. See Microsoft documentation for details.

Authentication

Watson services are migrating to token-based Identity and Access Management (IAM) authentication.

  • With some service instances, you authenticate to the API by using IAM.
  • In other instances, you authenticate by providing the username and password for the service instance.
  • If you're using a Watson service on ICP, you'll need to authenticate in a specific way.

Getting credentials

To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:

  1. Go to the IBM Cloud Dashboard page.
  2. Either click an existing Watson service instance or click Create resource > AI and create a service instance.
  3. Copy the url and either apikey or username and password. Click Show if the credentials are masked.

In your code, you can use these values in the service constructor or with a method call after instantiating your service.

IAM

Some services use token-based Identity and Access Management (IAM) authentication. IAM authentication uses a service API key to get an access token that is passed with the call. Access tokens are valid for approximately one hour and must be regenerated.

You supply either an IAM service API key or an access token:

  • Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
  • Use the access token if you want to manage the lifecycle yourself. For details, see Authenticating with IAM tokens. If you want to switch to API key override your stored IAM credentials with an IAM API key.

Supplying the IAM API key

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{versionDate}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
}

Supplying the access token

void Example()
{
    BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(
        bearerToken: "{bearerToken}");
    var service = new AssistantService("{versionDate}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
}

Username and password

void Example()
{
    BasicAuthenticator authenticator = new BasicAuthenticator(
        username: "{username}",
        password: "{password}");
    var service = new AssistantService("{versionDate}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
}

ICP

Like IAM, you can pass in credentials to let the SDK manage an access token for you or directly supply an access token to do it yourself.

Letting the SDK manage the token
void Example()
{
    CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
        url: "https://{cp4d_cluster_host}{:port}",
        username: "{username}",
        password: "{password}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
}
Managing the token yourself
void Example()
{
    BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(
        bearerToken: "{bearerToken}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Be sure to both disable SSL verification when authenticating and set the endpoint explicitly to the URL given in ICP.

Supplying credentials

There are two ways to supply the credentials you found above to the SDK for authentication.

Credential file (easier!)

With a credential file, you just need to put the file in the right place and the SDK will do the work of parsing it and authenticating. You can get this file by clicking the Download button for the credentials in the Manage tab of your service instance.

The file downloaded will be called ibm-credentials.env. This is the name the SDK will search for and must be preserved unless you want to configure the file path (more on that later). The SDK will look for your ibm-credentials.env file in the following places (in order):

  • The top-level directory of the project you're using the SDK in
  • Your system's home directory

As long as you set that up correctly, you don't have to worry about setting any authentication options in your code. So, for example, if you created and downloaded the credential file for your Discovery instance, you just need to do the following:

AssistantService service = new AssistantService("{version-date}");
var listWorkspacesResult = service.ListWorkspaces();

And that's it!

If you're using more than one service at a time in your code and get two different ibm-credentials.env files, just put the contents together in one ibm-credentials.env file and the SDK will handle assigning credentials to their appropriate services.

If you would like to configure the location/name of your credential file, you can set an environment variable called IBM_CREDENTIALS_FILE. This will take precedence over the locations specified above. Here's how you can do that:

export IBM_CREDENTIALS_FILE="{path}"

where {path} is something like /home/user/Downloads/{file_name}.env.

Manually

If you'd prefer to set authentication values manually in your code, the SDK supports that as well. The way you'll do this depends on what type of credentials your service instance gives you.

Custom Request Headers

You can send custom request headers by adding them to the service using .WithHeader({key}, {value}).

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    service.WithHeader("X-Watson-Metadata", "customer_id=some-assistant-customer-id");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Response Headers, Status Code and Raw Json

You can get the response headers, status code and the raw json response in the result object.

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
    
    var responseHeaders = results.Headers;  //  The response headers
    var responseJson = results.Response;    //  The raw response json
    var statusCode = results.StatusCode;    //  The response status code
}

Self signed certificates

You can disable SSL verification on calls to Watson (only do this if you really mean to!).

void Example()
{
    CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
        url: "https://{cp4d_cluster_host}{:port}",
        username: "{username}",
        password: "{password}",
        disableSslVerification: true);
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Transaction IDs

Every SDK call returns a response with a transaction ID in the X-Global-Transaction-Id header. Together the service instance region, this ID helps support teams troubleshoot issues from relevant logs.

AssistantService service = new AssistantService("{version-date}");
DetailedResponse<WorkspaceCollection> listWorkspacesResult = null;

try
{
    listWorkspacesResult = service.ListWorkspaces();

    //  Global transaction id on successful api call
    listWorkspacesResult.Headers.TryGetValue("x-global-transaction-id", out object globalTransactionId);
}
catch(Exception e)
{
    //  Global transaction on failed api call is contained in the error message
    Console.WriteLine("error: " + e.Message);
}

However, the transaction ID isn't available when the API doesn't return a response for some reason. In that case, you can set your own transaction ID in the request. For example, replace <my-unique-transaction-id> in the following example with a unique transaction ID.

void Example()
{
    IamAuthenticator authenticator = new IamAuthenticator(
        apikey: "{apikey}");
    var service = new AssistantService("{version-date}", authenticator);
    service.SetServiceUrl("{serviceUrl}");
    service.WithHeader("X-Global-Transaction-Id", "<my-unique-transaction-id>");
    var results = service.Message("{workspace-id}", "{message-request}");
}

Use behind a proxy

To use the SDK behind an HTTP proxy, you need to set either the http_proxy or https_proxy environment variable. You can set this in the application environment using:

set http_proxy=http://proxy.server.com:3128

from the cmd.

You can also set this in the application using:

Environment.SetEnvironmentVariable("http_proxy", "http://proxy.server.com:3128");

Documentation

Click here for documentation by release and branch.

Questions

If you have issues with the APIs or have a question about the Watson services, see Stack Overflow.

Open Source @ IBM

Find more open source projects on the IBM Github Page.

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.md.

Featured projects

We'd love to highlight cool open-source projects that use this SDK! If you'd like to get your project added to the list, feel free to make an issue linking us to it.

More Repositories

1

node-sdk

☄️ Node.js library to access IBM Watson services.
TypeScript
1,482
star
2

python-sdk

🐍 Client library to use the IBM Watson services in Python and available in pip as watson-developer-cloud
Python
1,452
star
3

speech-to-text-nodejs

🎤 Sample Node.js Application for the IBM Watson Speech to Text Service
JavaScript
1,086
star
4

swift-sdk

📱 The Watson Swift SDK enables developers to quickly add Watson Cognitive Computing services to their Swift applications.
Swift
880
star
5

java-sdk

🥇 Java SDK to use the IBM Watson services.
Java
586
star
6

unity-sdk

🎮 Unity SDK to use the IBM Watson services.
C#
570
star
7

personality-insights-nodejs

📊 Sample Nodejs Application for the IBM Watson Personality Insights Service
JavaScript
558
star
8

visual-recognition-coreml

Classify images offline using Watson Visual Recognition and Core ML
Swift
489
star
9

assistant-simple

A simple sample application demonstrating the Watson Assistant api.
JavaScript
482
star
10

tone-analyzer-nodejs

Sample Node.js Application for the IBM Tone Analyzer Service
CSS
452
star
11

text-to-speech-nodejs

This is a deprecated Watson Text to Speech Service Demo. A link to the newly supported demo is below
JavaScript
346
star
12

speech-javascript-sdk

Library for using the IBM Watson Speech to Text and Text to Speech services in web browsers.
JavaScript
256
star
13

node-red-labs

Node-RED labs on the use of the Watson Developer Cloud services
208
star
14

botkit-middleware

A middleware to connect Watson Conversation Service to different chat channels using Botkit
TypeScript
208
star
15

natural-language-classifier-nodejs

Deprecated: this demo will receive no further updates
JavaScript
158
star
16

android-sdk

🔆 Android SDK to use the IBM Watson services.
Java
145
star
17

assistant-with-discovery

DEPRECATED: this application is deprecated and thus will not receive fixes or security updates. It is archived for educational purposes, but may not function.
Java
145
star
18

natural-language-understanding-nodejs

🆕 Demo code for the Natural Language Understanding Service.
JavaScript
133
star
19

api-guidelines

👮 REST API guidelines created for the Watson Developer Cloud services
133
star
20

assistant-toolkit

Toolkit for experimentation with watsonx Assistant
HTML
100
star
21

car-dashboard

Application that demonstrates how the Watson Assistant service uses intent capabilities in an animated car dashboard UI.
JavaScript
91
star
22

node-red-node-watson

A collection of nodes for the IBM Watson services
HTML
83
star
23

discovery-nodejs

This is a deprecated Watson Discovery Service Demo. A link to the newly supported demo is below
JavaScript
76
star
24

go-sdk

🐭 go SDK for the IBM Watson services.
Go
71
star
25

assistant-improve-recommendations-notebook

Assistant Improve notebooks for Watson Assistant
Jupyter Notebook
68
star
26

investment-advisor

DEPRECATED: this repo is no longer actively maintained
JavaScript
66
star
27

speech-android-sdk

DEPRECATED - Please use https://github.com/watson-developer-cloud/android-sdk
Java
66
star
28

dialog-tool

DEPRECATED: this repo is no longer actively maintained
CSS
60
star
29

doc-tutorial-downloads

The download files from the IBM Watson Service documentation tutorials
Shell
57
star
30

language-translator-nodejs

Sample Node.js Application for the IBM Language Translator Service
CSS
51
star
31

sentiment-and-emotion

DEPRECATED: this repo is no longer actively maintained
CSS
50
star
32

simple-chat-swift

DEPRECATED: this repo is no longer actively maintained
Swift
48
star
33

ruby-sdk

♦️ Ruby SDK to use the IBM Watson services.
Ruby
45
star
34

raspberry-pi-speech-to-text

DEPRECATED: this repo is no longer actively maintained
JavaScript
44
star
35

food-coach

DEPRECATED: this repo is no longer actively maintained
JavaScript
39
star
36

assistant-skill-analysis

Dialog Skill Analysis framework for Watson Assistant
Jupyter Notebook
39
star
37

community

Example data that can be used for various Watson services
Shell
34
star
38

speech-to-text-swift

Speech-to-Text example using the Swift SDK
Swift
34
star
39

visual-recognition-code-pattern

JavaScript
33
star
40

react-components

DEPRECATED: this repo is no longer actively maintained
JavaScript
31
star
41

assistant-dialog-flow-analysis

Dialog Flow Analysis Notebook for Watson Assistant
HTML
28
star
42

salesforce-sdk

A Salesforce library for communicating with the IBM Watson REST APIs
Apex
28
star
43

conversation-connector

The Conversation connector is a set of components that mediate communication between your Conversation workspace and a Slack or Facebook app. Use the connector to deploy a chat bot that Slack or Facebook Messenger users can interact with.
JavaScript
27
star
44

document-conversion-nodejs

DEPRECATED: Please use https://github.com/watson-developer-cloud/discovery-nodejs
JavaScript
27
star
45

text-to-speech-java

DEPRECATED: this repo is no longer actively maintained
CSS
27
star
46

assistant-web-chat-service-desk-starter

A starter kit for building custom service desk integrations for Watson Assistant web chat
TypeScript
25
star
47

raspberry-pi-time-weather-demo

DEPRECATED: this repo is no longer actively maintained
JavaScript
24
star
48

assistant-demo

Assistant demo
JavaScript
23
star
49

discovery-starter-kit

IBM Watson Discovery Starter Kit
JavaScript
22
star
50

assistant-intermediate

An intermediate example of Watson Assistant in a Node.js application
JavaScript
22
star
51

discovery-components

IBM Watson Discovery components
TypeScript
22
star
52

assistant-with-discovery-openwhisk

DEPRECATED: this repo is no longer actively maintained
CSS
21
star
53

company-insights

DEPRECATED: this repo is no longer actively maintained
JavaScript
20
star
54

text-to-speech-swift

DEPRECATED: this repo is no longer actively maintained
Swift
20
star
55

social-customer-care

DEPRECATED: this repo is no longer actively maintained
CSS
19
star
56

speech-to-text-websockets-ruby

Ruby client that interacts with the IBM Watson Speech to Text service through its WebSockets interface
Ruby
19
star
57

customer-engagement-bot

DEPRECATED: this repo is no longer actively maintained
JavaScript
18
star
58

abap-sdk-nwas

ABAP code for using IBM Watson Developer Services with SAP NetWeaver Application Server, imported via abapGit
ABAP
18
star
59

assistant-web-chat

Language strings for web chat integration of IBM watsonx assistant
JavaScript
16
star
60

python-primer-companion-code

DEPRECATED: this repo is no longer actively maintained
Python
15
star
61

spring-boot-starter

Spring Boot support for Watson services
Java
13
star
62

personality-insights-java

DEPRECATED: this repo is no longer actively maintained
CSS
13
star
63

watson-developer-cloud.github.io

Index page with links to SDKs, docs, etc.
HTML
13
star
64

simple-chat-objective-c

DEPRECATED: this repo is no longer actively maintained
Objective-C
12
star
65

text-bot-openwhisk

DEPRECATED: this repo is no longer actively maintained
JavaScript
12
star
66

ui-components

DEPRECATED: this repo is no longer actively maintained
CSS
12
star
67

openwhisk-sdk

🆕 SDK for using Watson Services on IBM Cloud Functions (based on Apache Openwhisk) - DEPRECATED
JavaScript
12
star
68

app-insights-discovery

DEPRECATED: this repo is no longer actively maintained
Swift
10
star
69

customer-engagement-nodejs

Customer Engagement
JavaScript
10
star
70

token-generator

Basic Node.js Server to generate watson auth tokens from user-supplied credentials.
JavaScript
6
star
71

watson-vision-coreml-code-pattern

Watson Visual Recognition CoreML Code Pattern
CSS
5
star
72

abap-sdk-scp

ABAP code for using IBM Watson Developer Services with SAP Cloud Platform, imported via abapGit with dependencies via APACK
ABAP
5
star
73

restkit

Core networking and authentication library for the Watson Swift SDK
Swift
4
star
74

cognitive-client-java

DEPRECATED: this repo is no longer actively maintained
Java
4
star
75

speech-to-text-utils

Speech to text CLI that helps you manage speech customizations.
JavaScript
4
star
76

homebrew-tools

DEPRECATED: this repo is no longer actively maintained
Ruby
3
star
77

language-translator-tooling

DEPRECATED: this repo is no longer actively maintained
JavaScript
2
star
78

natural-language-classifier-intent-classification-demo

Deprecated
JavaScript
2
star
79

discovery-nodejs-static

Sample Node.js application that uses the IBM Watson Discovery Service
JavaScript
2
star
80

natural-language-understanding-code-pattern

Natural Language Understanding Code Pattern
JavaScript
2
star
81

speech-to-text-code-pattern

React app using the Watson Speech to Text service to transform voice audio into written text.
JavaScript
2
star
82

swift-playgrounds

Swift playgrounds for Watson Developer Cloud services
Swift
2
star
83

sdk-example-editor

Web application that helps edit SDK examples from an OpenAPI file.
JavaScript
1
star
84

actions-logging-server

HTML
1
star
85

Watson-Assistant-Workspace-Retrain

Python
1
star
86

actions-analytics-dashboard

JavaScript
1
star
87

assistant-web-chat-react

A React library to make integration of Watson Assistant web chat with a React application easy.
TypeScript
1
star
88

visual-recognition-utils

Command line tools to make creating & managing Watson Visual Recognition Custom Classifiers easier.
JavaScript
1
star