0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Node-RED にて Watson Assistant APIにおける user_id のセット方法

Last updated at Posted at 2021-04-05

背景

Watson Assistant 用ノード(node-red-node-watson 0.94 の 『watson-assistant-v2』)において、ノードの情報(github上ソースコードコード内の data-help-name="watson-assistant-v2"部分 )を見る限り、user_id をセットする機能が提供されていないようだったので、新たに、user_idをセットする機能を含めたAssistant用のfunction ノードを作成したので、備忘録として整理した。

具体的な方法

今回は、以下の内容を、function内で記述するために、APIリファレンス(Watson Assistant v2用)を参考に、ステートレス形式で作成した。

curl -X POST -u "apikey:{apikey}" --header "Content-Type:application/json" --data "{\"input\": {\"text\": \"Hello\"}}" "{url}/v2/assistants/{assistant_id}/message?version=2020-04-01"

<ポイント>

  • apikeyを渡すために、Authorizationヘッダーをセット(msg.headers へセット)
  • "apikey:{apikey}" の部分(以下の%%%%%)は、base64にてエンコーディングしたものをセットする
  • msg.urlに、エンドポイントを指定
  • msg.payload 内に、json形式で、user_id にセットしたいユーザーIDをセット(例では、test_user をセット)
  • 下記のように作成したfunctionノードと、http requestノード(post)を接続
  • 今回は、ステートレス用として作成(下記の例もステートレス用)
Assistant用functionノード

//msg.payload.input には問い合わせする内容がセットされている
input_data = msg.payload.input ;
msg.headers =  {"Authorization": "Basic %%%%%","Content-Type":"application/json"};
msg.url = 'https://api.au-syd.assistant.watson.cloud.ibm.com/instances/xxxxx/v2/assistants/yyyyy/message?version=2020-04-01' ;
msg.payload = '{"input": {"text":"' + input_data + '"},"user_id":"test_user"}' ;
return msg;

関連記事

1.Watson Assistantの新しいプラン「Plus」と月次ユーザー数課金(MCU)導入のご紹介
2.BASIC認証の越え方
3.Watson Assistant API V1/V2の違い

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?