5
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.

Power Virtual Agents: 変数についてのまとめ

Last updated at Posted at 2021-12-03

背景

会社で以下質問を受けたので試してみた記録

ボット変数のリセット方法が分かりますか? トピックA⇒C、トピックB⇒C で動かすと、トピックA⇒Cで動かしたときの結果が残ってるんです。

分かったこと

「質問する」を追加することで作成する。

逆に言うと・・これでしか、作成出来ない
image.png

Create a variable によると、

In the bot authoring canvas, add a question node by choosing Ask a question. A variable will be automatically created within the node.

他に生成方法が無いかと探したけど、現状見つからず・・。上記マニュアルの通りかな、と

変数の設定

  • トピック:対象トピック内だけで利用可能。
    「別のトピックにリダイレクトする」を利用することで、以下が効いてくる
    • 他のトピックから・・:他のトピックから受け取ることが可能。と言いつつ、質問で上書きされるので意味不明
    • 値を元のトピックに・・:Return して結果を返すことが可能
  • ボット:トピック間で利用可能
    • 外部ソース・・:外部(Power Automate とか)で設定することが可能

image.png

他のトピックから・・・

渡す値が、変数と整合取れていれば普通に渡せるが、不整合の場合はエラー
※以下の場合、選択肢外の変数を入れているからエラーが出てると認識
image.png

で、参照元から渡されてる場合、質問が省略される。
故に、複数のトピックからリダイレクトした場合、Call元の値をそのまま利用することが可能そう
image.png

しかしながら、同一トピックへの複数リダイレクトの場合は、二回目以降では、引数は利用されず質問されることになる。
image.png

値を元のトピックに・・・

こんな感じで使うことでトピックの結果を受け取り可能
image.png

変数の初期化タイミング

Life Cycle によると、最初からやり直す場合と、変数の生成トピックを呼び出された時。

The value is only cleared when the bot user is redirected to the Start over system topic, or when the user triggers this topic directly (for example, by typing Start over). In this case, all bot variables will be reset and won't have any values.

変数が初期化されてなかった場合の動作

initialization によると、参照トピックが呼び出された際に未初期化だった場合、変数の生成トピックが事前に呼び出されることになる。

If a bot variable is triggered before it has been initialized (or "filled in"), the bot will automatically trigger the part of the topic where the bot variable is first defined—even when it's in a different topic—before returning to the original topic. This allows the bot to have all the variables filled in without interrupting the conversation.

実例
image.png

考察

  • 変数のリセット方法は無い
  • 複数のトピックの結果を共通して利用することは可能。
    • 同一トピックを複数回リダイレクトすることがあると問題はあるけどそんな使い方はたぶんしない筈
  • Bot変数を利用すると、必須質問をトピックにまとめておくことで、必要な時に勝手に呼ばれるように出来そう
  • Automateからの受取もまた便利そうね

いい感じで使えそうなことが見えてきた。
あとは、もうちょいメンテしやすい仕組みにしてくれるとありがたいなぁ

5
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
5
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?