vania-janet/multiturn-rag-retrieval-data huggingface dataset:
If you want to handle authorization yourself, add your own authorization header and it will be used instead.

After you save the header value, the string is replaced by asterisks and can't be viewed again.



Your webhook details are saved automatically.





 Testing the webhook 

Do extensive testing of your webhook before you enable it for an assistant that is being used in a production environment.

The webhook is triggered when a message is sent to your assistant to be processed.

If you enable the setting that returns an error when the webhook call fails, the processing of the assistant is halted entirely if the webhook encounters any issues. Take steps to test the process that you are calling on a regular basis so you will be alerted if the external service is down, and can take actions to prevent all of the incoming messages from failing to be recieved.

If you call an Cloud Functions web action, you can use the logging capability in Cloud Functions to help you troubleshoot your code. You can [download the command line interface](https://cloud.ibm.com/functions/learn/cli), and then enable logging with the [activation polling command](https://cloud.ibm.com/docs/cloud-functions-cli-plugin?topic=cloud-functions-cli-plugin-functions-clicli_activation_poll).





 Troubleshooting the webhook 

The following error codes can help you track down the cause of issues you might encounter. If you have a web chat integration, for example, you will know that your webhook has an issue if every test message you submit returns a message such as, There is an error with the message you just sent, but feel free to ask me something else. If this message is displayed, use a REST API tool, such as cURL, to send a test /message API request, so you can see the error code and full message that is returned.



Error code details

 Error code and message Description 

 422 Webhook responded with invalid JSON body The webhook's HTTP response body could not be parsed as JSON. 
 422 Error validating webhook response The webhook's HTTP response body was not a valid /message body.
To show examples of results with all possible combinations of the parameters, the arguments for interim_results and low_latency are set to true or false in the examples in the following sections.

var access_token = {access_token};
var wsURI = '{ws_url}/v1/recognize'
+ '?access_token=' + access_token
+ '&model=en-US_Telephony';
var websocket = new WebSocket(wsURI);

websocket.onopen = function(evt) { onOpen(evt) };
function onOpen(evt) {
var message = {
action: 'start',
content-type: 'audio/wav',
inactivity_timeout: -1,
interim_results: {true | false},
low_latency: {true | false}
};
websocket.send(JSON.stringify(message));
websocket.send(blob);
}

websocket.onmessage = function(evt) { onMessage(evt) };
function onMessage(evt) {
console.log(evt.data);
}
Show more

The WAV file that is passed to the service includes a single sentence with two embedded multi-second pauses: "Thunderstorms could produce ...pause... large hail ...pause... and heavy rain." The pauses are long enough to represent separate utterances and thus generate multiple final results. Because each response includes multiple final results, one per utterance, you must assemble the final results into a single string to see the full transcript.



 Example 1: Interim results and low latency are both false 

This example sets both interim_results and low_latency to false. The service returns only final results as a single JSON object.

var message = {
action: 'start',
content-type: 'audio/wav',
inactivity_timeout: -1,
* URL: https://us-south.functions.appdomain.cloud/api/v1/web/e97d2516-5ce4-4fd9-9d05-acc3dd8ennn/default/check_language
* Secret: none
* Header name: Content-Type
* Header value: application/json



The premessage webhook calls an IBM Cloud Functions web action name check_language.

The node.js code in the check_language web action looks as follows.

let rp = require("request-promise");

function main(params) {
console.log(JSON.stringify(params))
if (params.payload.input.text !== '') {
// Send a request to the Watson Language Translator service to check the language of the input text.
const options = { method: 'POST',
url: 'https://api.us-south.language-translator.watson.cloud.ibm.com/instances/572b37be-09f4-4704-b693-3bc63869nnnn/v3/identify?version=2018-05-01',
auth: {
'username': 'apikey',
'password': 'nnn'
},
headers: {
"Content-Type":"text/plain"
},
body: [
params.payload.input.text
],
json: true,
};
return rp(options)
.then(res => {
params.payload.context.skills["actions skill"].user_defined["language"] = res.languages[0].language;
console.log(JSON.stringify(params))
//Append "in" plus "the language code" to the input text, surrounded by parentheses.
const response = {
body : {
payload : {
input : {
* secret: the optional secret or API key needed to use the webhook.



3. When all variables are initiated, create the webhook:



curl -X POST https://api.cis.cloud.ibm.com/v1/:crn/alerting/destinations/webhooks
-H 'content-type: application/json'
-H 'x-auth-user-token: Bearer xxxxxx'
-d '{"name":"Example Webhook","url":"https://hooks.slack.com/services/Ds3fdBFbV/456464Gdd"}'





 Listing all webhooks using the API 

To list all webhooks by using the API, follow these steps:



1. Set up your API environment with the correct variables.
2. Store your the following variable to be used in the API command:



* crn: the full url-encoded CRN of the service instance.



3. When all variables are initiated, get the list of webhooks:



curl -X GET https://api.cis.cloud.ibm.com/v1/:crn/alerting/destinations/webhooks
-H 'content-type: application/json'
-H 'accept: application/json'
-H 'x-auth-user-token: Bearer xxxxxx'





 Getting details for a webhook using the API 

To get the details of a webhook by using the API, follow these steps:



1. Set up your API environment with the correct variables.
2. Store your the following variable to be used in the API command:



* crn: the full url-encoded CRN of the service instance.
* webhook_id: alert webhook identifier.



3. When all variables are initiated, get the webhook details:



curl -X GET https://api.cis.cloud.ibm.com/v1/:crn/alerting/destinations/webhooks/:webhook_id
* <ENDPOINT> represents the endpoint that is targetted by the REST API call. For more information, see [Monitoring REST API endpoints](https://cloud.ibm.com/docs/monitoring?topic=monitoring-endpointsendpoints_rest_api). For example, the public endpoint for an instance that is available in us-south is the following: https://us-south.monitoring.cloud.ibm.com/api
* <TOKEN> API token that you use to authenticate with the Monitoring service. You must include Bearer with the token. For more information, see [Working with Monitoring API tokens](https://cloud.ibm.com/docs/monitoring?topic=monitoring-api_monitoring_token).
* <STREAMING_CONFIG_ID> represents the UUID of the streaming configuration for which you want to get details.



The response will be similar to the following:

{
"dataStreamConfig": {
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"enabled": true,
"name": "Streaming metrics - demo",
"emitterType": "kafka",
"emitterProperties": {
"bootstrap.servers": "kafka-0.mh-svc1.eu-de.containers.appdomain.cloud:9093, kafka-2.mh-svc2-0000.eu-de.containers.appdomain.cloud:9093,kafka-1.mh-svc3.eu-de.containers.appdomain.cloud:9093",
"topic.name": "my-monitoring-topic",
"compression.type": "lz4",
"security.protocol": "SASL_SSL",
"sasl.mechanism": "PLAIN",
// Returns a signed JWT signed with the RS256 algorithm.
function createJWT() {
const payload = {
sub: 'some-user-id', // Identifies user for billing purposes
};
// The "expiresIn" option adds an "exp" claim to the payload.
return jwt.sign(payload,
process.env.YOUR_PRIVATE_RSA_KEY,
{ algorithm: 'RS256', expiresIn: '1h' });
}





 Configuring the web chat to include JWTs 

Now that you have implemented a function to generate a signed JWT, you must update your web chat instance to include the signed JWT with each message it sends. After you enable web chat security, any messages that are not signed with the proper private key are rejected.

In your website HTML, update the web chat embed script to specify a new JWT at the beginning of each session, and also whenever the existing JWT expires. The simplest way to do this is to subscribe to the [identityTokenExpired](https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-eventsidentityexpired) event and generate a new JWT when that event is received. The identityTokenExpired event is fired in both of the following situations:



* At the beginning of a new session, if no JWT was provided using the identityToken configuration option.
* When the previously specified JWT expires.



In your onLoad event handler, use the [on()](https://web-chat.global.assistant.watson.cloud.ibm.com/docs.html?to=api-instance-methodson) instance method to subscribe to the identityTokenExpired event.

In the callback, call the function on your server that you implemented to generate a new JWT. Then use the identityToken parameter of the event to specify the new JWT, as in this example:

instance.on({ type: 'identityTokenExpired',
handler: async function(event) {
See also [Secure Sockets Layer](https://cloud.ibm.com/docs/overview?topic=overview-glossaryx2038004), [intermediate certificate](https://cloud.ibm.com/docs/overview?topic=overview-glossaryx3753781), [trusted root](https://cloud.ibm.com/docs/overview?topic=overview-glossaryx2042234).





 certificate signing request (CSR) 

An electronic message that an organization sends to a certificate authority (CA) to obtain a certificate. The request includes a public key and is signed with a private key; the CA returns the certificate after signing with its own private key.





 chaincode 

Executable code that contains business logic agreed to by a set of organizations on a channel. A chaincode, and the smart contracts it contains, is installed on peers, instantiated on a channel, and governs access to the ledger data that is generated through invocations of the chaincode. See also [transaction](https://cloud.ibm.com/docs/overview?topic=overview-glossaryx2005321).





 channel 

A private subset of a larger blockchain network with specific rules and a separate ledger that only channel members can access.





 CLI 

See [command-line interface](https://cloud.ibm.com/docs/overview?topic=overview-glossaryx2051424).





 client 



* An entity that acts on behalf of a user by connecting to a peer to communicate with the blockchain.
* A software program or computer that requests services from a server. See also [host](https://cloud.ibm.com/docs/overview?topic=overview-glossaryx2002243).







 client secret 

A piece of information that is used with an application key to verify the identity of an application. An API can be configured to require that client applications supply their application secret with their application key. The application secret functions effectively as a password known only to the application. The application secret is passed by the client using an HTTP query parameter.





 cloud computing
const RSA = require('node-rsa');

const rsaKey = new RSA(process.env.PUBLIC_IBM_RSA_KEY);

/
* Returns a signed JWT. Optionally, also adds an encrypted user payload
* as stringified JSON in a private claim.
/
function mockLogin(userID, userPayload) {
const payload = {
sub: userID, // Required
// The exp claim is automatically added by the jsonwebtoken library.
};
if (userPayload) {
// If there is a user payload, encrypt it using the IBM public key
// and base64 format.
payload.user_payload = rsaKey.encrypt(userPayload, 'base64');
}
const token = jwt.sign(payload, process.env.YOUR_PRIVATE_RSA_KEY, { algorithm: 'RS256', expiresIn: '1h' });
return token;
}
Show more

The user payload must be valid JSON data. The web chat uses the default options of the [Node-RSA](https://www.npmjs.com/package/node-rsa) library, which expects the encryption scheme pkcs1_oaep and the encryption encoding base64.
4. When the web chat integration receives a message signed with this JWT, the content of the user_payload claim is decrypted and saved as the context.integrations.chat.private.user_payload object. Because this is a private variable, it will not be included in logs.
Using Kafka Streams with Event Streams 

Kafka Streams is a stream processing library that is part of the Apache Kafka project. It simplifies building applications that process and analyze data in Kafka.

The topic APIs work with Event Streams with no setup required. Specify your SASL credentials by using sasl.jaas.config or a JAAS file and set replication.factor to 3.

Ensure that you use Streams version 0.10.2, or later.

See the following example:

props.put(StreamsConfig.REPLICATION_FACTOR_CONFIG, "3");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put("security.protocol","SASL_SSL");
props.put("sasl.mechanism","PLAIN");
props.put("ssl.protocol","TLSv1.2");
props.put("ssl.enabled.protocols","TLSv1.2");
props.put("sasl.jaas.config","org.apache.kafka.common.security.plain.PlainLoginModule required username="USERNAME" password="PASSWORD";");

Where BOOTSTRAP_SERVERS, USERNAME, and PASSWORD are the values from your Event Streams Service Credentials tab in IBM Cloud.
The alphanumeric text to be synthesized is a hexadecimal string that is wrapped in a <say-as> element and interpreted as digits.

IBM Cloud

curl -X POST -u "apikey:{apikey}" --header "Content-Type: application/json" --header "Accept: audio/wav" --output spell-out-mode.wav --data "{"text":"Die Nummer ist <say-as interpret-as=‘digits’>AB7234987FFA</say-as>."}" "{url}/v1/synthesize?voice=de-DE_ErikaV3Voice&spell_out_mode=singles"

IBM Cloud Pak for Data

curl -X POST --header "Authorization: Bearer {token}" --header "Content-Type: application/json" --header "Accept: audio/wav" --output spell-out-mode.wav --data "{"text":"Die Nummer ist <say-as interpret-as=‘digits’>AB7234987FFA</say-as>."}" "{url}/v1/synthesize?voice=de-DE_ErikaV3Voice&spell_out_mode=singles"

The following WebSocket example shows inclusion of the parameter with the same value on the request to establish a connection:

var access_token = '{access_token}';
var wsURI = '{ws_url}/v1/synthesize'
+ '?access_token=' + access_token
+ '&voice=de-DE_ErikaV3Voice'
+ '&spell_out_mode=singles';
var websocket = new WebSocket(wsURI);
Create and send push notifications to Firefox web by using Event Notifications 

Create an Event Notifications service, add a push destination for Firefox, and send messages to Firefox web devices.



 What is Event Notifications? 

Event Notifications is an event notification routing service that notifies you of critical events that occur in your IBM Cloud account or triggers automated actions by using webhooks. You can filter and route event notifications from IBM Cloud services like Availability Monitoring, to email, SMS, push notifications, and webhooks.





 How do clients use Firefox web push notifications? 

The following diagram shows you how clients use Firefox web Push Notifications.

Zoom

![How clients use push notifications](https://cloud.ibm.com/docs-content/v1/content/4c9a07fe500838e5e55e71e73131ef20b44a6c66/event-notifications/images/en-how-send-mozilla.svg)

Figure 1. How clients use push notifications





 Objectives 

This tutorial shows you how to send push notifications as follows:



* Create a website with Event Notifications.
* Get Firefox web credentials.
* Download the SDK and complete the notifications setup.
* Configure and send Firefox web Push Notifications to a browser.







 Step 1: Create an Event Notifications service instance 



* Log in to your [IBM Cloud account](https://cloud.ibm.com/).
* In the [IBM Cloud catalog](https://cloud.ibm.com/catalogservices), search Event Notifications > Event Notifications.
* Select a Region from the list of supported regions and select a pricing plan.
* Provide a Service name.
* Select a resource group.
* Accept the licensing agreements and terms by clicking the checkbox.
* Click Create.







 Step 2: Add a generic API source 

Take the following steps:



* Go to the Sources section of the Event Notifications dashboard.
* Click Add and select an API Source.
Feed A [feed](https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-triggerstriggers_feeds) is a convenient way to configure an external event source to fire trigger events that can be consumed by Cloud Functions. For example, a Git feed might fire a trigger event for every commit to a Git repository. 
 Package Integrations with services and event providers can be added with packages. A [package](https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-pkg_ov) is a bundle of feeds and actions. An existing catalog of packages offers a quick way to enhance applications with useful capabilities, and to access external services in the ecosystem. Examples of external services that have Cloud Functions packages include IBM Cloudant, Slack, and GitHub. 







 What happens behind the scenes in Cloud Functions? 

Cloud Functions is based on OpenWhisk, an open source project that combines components such as NGINX, Kafka, Docker, and CouchDB to form a serverless event-based programming service.

Zoom

![The internal flow of processing behind the scenes in OpenWhisk.](https://cloud.ibm.com/docs-content/v1/content/adc643f3bedeea02b638bc1c34732852dcb40a45/openwhisk/images/OpenWhisk_flow_of_processing.png)

Figure 1. The internal flow of processing behind the scenes in OpenWhisk



 1. Entering the system: NGINX 

The first entry point into the system is through NGINX, an HTTP and reverse proxy server. NGINX is used for SSL termination and forwarding appropriate HTTP calls to the next component.

The OpenWhisk user-facing API is HTTP-based and follows a RESTful design. As a consequence, the command that is sent through the CLI is an HTTP request against the OpenWhisk system. The specific command translates roughly to the following syntax:
You can access the v2 endpoint in the same way as the existing URL, which is by obtaining the value of kafka_http_url property for the service instance. The path to use is /v2/topics/<topic_name>/records.

Example URL: https://service-instance-adsf1234asdf1234asdf1234-0000.us-south.containers.appdomain.cloud/v2/topics/topic_name/records
2. Authentication:

The supported authentication mechanism is a bearer token. To enhance security, basic authentification by using API keys is no longer accepted.

Example Header: -H "Authorization: Bearer $token"
3. Headers:

Set the Content-Type and the Accept headers to application/json.

Example Headers: -H "Content-Type: application/json" -H "Accept: application/json"
4. Payload:

Provide the payload for the v2 endpoint in JSON format. The message key, headers, and data can be defined in the payload. You can specify the headers in the form of a list, with values that are base64 encoded. However, the message key and headers are optional.

Example payload:
{
"headers": [
{
"name": "colour",
"value": "YmxhY2s="
},
"key": {
"type": "text",
"data": "Test Key"
},
"value": {
"type": "text",
"data": "Test Value"
}
}
Show more

You must specify one of the following supported data types for the field type under the key and value object:

a. Text: the data that is provided is validated as plain text format that consists of a linear sequence of characters.

b. Binary: the data that is provided is validated as base64-encoded binary format.

c.
Next, test that your notifications are now delivered as a signed JWT objects to your [Webhook.site](https://webhook.site) page. You can use the Settings > Event Notifications section in the Secrets Manager UI to [send a test event](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-event-notificationsevent-notifications-test-ui). The output of a signed notification payload looks similar to the following example.

eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiYXV0aG9yIjp7...(truncated)

To verify the signature and decrypt the message, you'll need to obtain the public key that is generated by Event Notifications. Continue to the next step.







 Step 3: Prepare your sample code 

Next, prepare the sample code for your Cloud Functions action.



1. Copy the following JavaScript code and update the placeholder values.

const axios = require('axios');
const jwtVerify = require('jsonwebtoken').verify;

// Generate an IAM token
async function getIAMToken() {
const options = {
url: 'https://iam.cloud.ibm.com/identity/token',
method: 'POST',
header: 'Content-Type: application/x-www-form-urlencoded',
data: 'grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=API_KEY'
};

const response = await axios(options);
const responseData = response.data;
console.log("nGenerated an IAM token..");
return responseData.access_token;
}

// Get a public key to verify notifications
async function getPublicKey() {
const accessToken = await getIAMToken();
[librdkafka](https://github.com/edenhill/librdkafka) C or C++ Latest 0.11.0 







 Connecting your client to Event Streams 

For information about how to configure your Java client to connect to Event Streams, see [Configuring your client](https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-kafka_usingkafka_api_client).







 Configuring your Kafka API client 

To establish a connection, clients must be configured to use SASL PLAIN or SASL OAUTHBEARER over TLSv1.2 at a minimum and to require a username, and a list of the bootstrap servers. TLSv1.2 ensures that connections are encrypted and validates the authenticity of the brokers (to prevent man-in-the-middle attacks). SASL enforces authentication on all connections.

To retrieve the username, password, and list of bootstrap servers, a service credentials object, or service key is required for the service instance. For more information about creating these objects, see [Connecting to Event Streams](https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-connecting).



 Using SASL PLAIN 

Use the following strings and properties.



* Use the bootstrap_endpoints string as the list of bootstrap servers and pass this string of host and port pairs to your Kafka client.
* Use the user and api_key properties as the username and password.



For a Java client, the following example shows the minimum set of properties, where ${USERNAME}, ${PASSWORD}, and ${BOOTSTRAP_ENDPOINTS} are to be replaced by the values that you retrieved previously.

bootstrap.servers=${BOOTSTRAP_ENDPOINTS}
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="${USERNAME}" password="${PASSWORD}";