skype for business + bot + graph api

73
第19回 Office 365 勉強会 2017年6月3日 瀬尾佳隆 (@seosoft) Microsoft MVP for Windows Dev Skype for Business + Bot + Graph API

Upload: yoshitaka-seo

Post on 22-Jan-2018

47 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Skype for Business + Bot + Graph API

第19回 Office 365 勉強会2017年6月3日

瀬尾佳隆 (@seosoft)Microsoft MVP for Windows Dev

Skype for Business + Bot

+ Graph API

Page 2: Skype for Business + Bot + Graph API

おことわり

本資料は、2017年6月3日時点の内容です

Slideshare 公開した 2018年1月時点では一部古い内容を含んでいることがありますが、記録・参考として公開します

Page 3: Skype for Business + Bot + Graph API

自己紹介

瀬尾佳隆 (せおよしたか)•MVP for Windows Development• http://yseosoft.wordpress.com/• 乃木坂46 / 欅坂46 と、仏像 / 屏風絵が好き

Cogbot コミュニティ スタッフ

Techfair 主宰

3

Page 4: Skype for Business + Bot + Graph API

今日の内容

Bot Framework の概要

Skype for Business 対応

Bot で Graph API 利用

操作手順、コード例は資料後半に「おまけ」として載せてます

4

Page 5: Skype for Business + Bot + Graph API

この資料の置き場所

http://bit.ly/s4bbot_20170603

“Skype for Business” + “Bot” + 今日の日付

5

Page 6: Skype for Business + Bot + Graph API

今日の皆さんの宿題

Bot Framework がSkype for Business に対応• Preview なので、まだまだ課題があるのは事実

•企業内システムでもChat インターフェイスが増えるはず

今のうちにアイデアを練ってください

6

Page 7: Skype for Business + Bot + Graph API

Build 2017

Bot Framework 関連のアップデート• Channel 追加

• Skype for Business

• Adaptive Card• LUIS 連携の強化• Speech 対応

など

7

Page 8: Skype for Business + Bot + Graph API

Bot Framework の概要

8

Page 9: Skype for Business + Bot + Graph API

Bot とは

ユーザーとシステムとのコミュニケーションはDialog で行われる (Screen ではない)

https://docs.microsoft.com/en-us/bot-framework/bot-design-conversation-flow9

Page 10: Skype for Business + Bot + Graph API

Bot のアーキテクチャー

https://docs.microsoft.com/en-us/bot-framework/overview-how-bot-framework-works10

Page 11: Skype for Business + Bot + Graph API

Bot のアーキテクチャー

https://docs.microsoft.com/en-us/bot-framework/overview-how-bot-framework-works

ユーザーBot サービス 直接通信しているわけではない

11

Page 12: Skype for Business + Bot + Graph API

Bot Framework

https://dev.botframework.com/

Bot 作成のツール、管理ポータルの集合体•開発ツール• Bot 登録管理• Bot Directory•ドキュメント

12

Page 13: Skype for Business + Bot + Graph API

Bot 開発に必要なもの

Bot Builder SDK

Bot Application Template

Bot Framework Emulator

Bot Connector

13

Page 14: Skype for Business + Bot + Graph API

Bot Builder SDK

Bot 開発のためのライブラリ / API セット• Bot Builder SDK for .NET• Bot Builder SDK for Node.js• Azure Bot Service• REST API

14

Page 15: Skype for Business + Bot + Graph API

Bot Application Template

Visual Studio 用のプロジェクトテンプレート• http://aka.ms/bf-bc-vstemplate• ZIP ファイルのままで、“%USERPROFILE%¥Documents¥Visual Studio 2017¥Templates¥ProjectTemplates¥Visual C#¥” にコピー

15

Page 16: Skype for Business + Bot + Graph API

Bot Framework Emulator

Bot のデバッグツール• https://docs.microsoft.com/en-us/bot-framework/debug-bots-emulator

•会話の流れ•会話の生データ (json)•ログ

16

Page 17: Skype for Business + Bot + Graph API

Bot Connector

Bot と Chat アプリとを接続する仕組み• Chat アプリごとに Bot のコードを変更する必要がない• Skype for Business が追加された (Build 2017)

17

Page 18: Skype for Business + Bot + Graph API

Skype for Business 対応

18

Page 19: Skype for Business + Bot + Graph API

現在は Preview

今後に期待 何を言いたいのか察してください・・・

https://msdn.microsoft.com/en-us/skype/Skype-For-Business-Bot-Framework/docs/overview19

Page 20: Skype for Business + Bot + Graph API

Bot Connector (再確認)

Bot と Chat アプリとを接続する仕組み• Chat アプリごとに Bot のコードを変更する必要がない

Chat アプリの種類によらず接続可能

20

Page 21: Skype for Business + Bot + Graph API

Skype for Business + Bot

Bot と Skype for Business との接続もOK• Skype for Business でも Bot を変更する必要ない

Skype for Businessであっても Bot 変更不要

Preview なので、いろいろ課題はあるんですが・・・

21

Page 22: Skype for Business + Bot + Graph API

現在の課題

シングルサインインできない•認証されているのは Skype クライアント• Bot はユーザーが認証されていることを知らない

• Bot では Chat アプリ固有のコードは記述しない

Bot のプレゼンスが取れない•オンラインでないと話しかけづらいかも

22

Page 23: Skype for Business + Bot + Graph API

認証の方法

方法は 2つ•OAuth 認証のコードを自力で書く• AuthBot パッケージを使う

• ただし AuthBot は非公式、かつプレビューなので制約が多い

23

Page 24: Skype for Business + Bot + Graph API

AuthBot

現在 Preview 版、非公式パッケージ

24

Page 25: Skype for Business + Bot + Graph API

AuthBot の注意点

依存関係のある NuGet パッケージのバージョン縛りがある•全パッケージを最新にするとビルドエラーや実行時エラー

• Preview が取れるのを待ちましょう

2017年6月2日現在、最新バージョンにしては

いけないパッケージ25

Page 26: Skype for Business + Bot + Graph API

AuthBot 実行結果 (1/4)

認証情報の要求

26

Page 27: Skype for Business + Bot + Graph API

AuthBot 実行結果 (2/4)

認証

27

Page 28: Skype for Business + Bot + Graph API

AuthBot 実行結果 (3/4)

マジックナンバーを送信

28

Page 29: Skype for Business + Bot + Graph API

AuthBot 実行結果 (4/4)

認証成功

29

Page 30: Skype for Business + Bot + Graph API

Bot で Graph API 利用

30

Page 31: Skype for Business + Bot + Graph API

認証できたら、次は

Graph API 利用•Graph エクスプローラーがあれば、アプリ実装は意外と簡単

31

Page 32: Skype for Business + Bot + Graph API

Graph エクスプローラー

Graph API の呼び出し方を確認するのに便利

https://developer.microsoft.com/ja-jp/graph/graph-explorer 32

Page 33: Skype for Business + Bot + Graph API

Graph API 呼び出し方

Graph API 呼び出しは定石通りGraph エクスプローラーの

クエリをペースト(必要に応じて加工)

33

Page 34: Skype for Business + Bot + Graph API

モデルの例 (1/2)

ユーザー情報の場合

34

Page 35: Skype for Business + Bot + Graph API

モデルの例 (2/2)

カレンダー情報の場合

35

Page 36: Skype for Business + Bot + Graph API

実行例

36

Page 37: Skype for Business + Bot + Graph API

参考

37

Page 38: Skype for Business + Bot + Graph API

情報源

Bot Framework• https://dev.botframework.com/

SecuretaryBot 開発チーム Blog• https://secretarybotja.wordpress.com/

Cogbot コミュニティ• https://www.facebook.com/groups/cogbot/

瀬尾のセッション資料 (Cogbot 関連)• https://docs.com/yoshitaka-seo/2037/cogbot

38

Page 39: Skype for Business + Bot + Graph API

第6回 Cogbot 勉強会

Build 2017, de:code 2017 最新情報

2017年6月16日 (金) 19:30 開始https://cogbot.connpass.com/event/58638/

39

Page 40: Skype for Business + Bot + Graph API

おまけ 1Bot 開発のポイント

40

Page 41: Skype for Business + Bot + Graph API

コーディングのポイント

41

Page 42: Skype for Business + Bot + Graph API

コーディングのポイント (1/5)

IDialog を実装したクラスで、ユーザーとBotとの対話を処理

42

Page 43: Skype for Business + Bot + Graph API

コーディングのポイント (2/5)

ここまでの対話の必要な内容を保持できる

43

Page 44: Skype for Business + Bot + Graph API

コーディングのポイント (3/5)

ユーザーが送信してきたメッセージ

44

Page 45: Skype for Business + Bot + Graph API

コーディングのポイント (4/5)

Bot からユーザーに返すメッセージ

45

Page 46: Skype for Business + Bot + Graph API

コーディングのポイント (5/5)

ユーザーからの次のメッセージを待つ

46

Page 47: Skype for Business + Bot + Graph API

おまけ 2Bot 登録手順

47

Page 48: Skype for Business + Bot + Graph API

Bot 登録手順 (1/8)

Bot を Azure App Service に展開

あとで使います

48

Page 49: Skype for Business + Bot + Graph API

Bot 登録手順 (2/8)

Bot Framework の My bots で[Create a bot]

49

Page 50: Skype for Business + Bot + Graph API

Bot 登録手順 (3/8)

名前、ハンドル、説明を入力

50

Page 51: Skype for Business + Bot + Graph API

Bot 登録手順 (4/8)

Bot のエンドポイントを入力•サイト URL を “https” にして、末尾に “api/messages”

正確には Bot のController名

51

Page 52: Skype for Business + Bot + Graph API

Bot 登録手順 (5/8)

[Create Microsoft App ID and password]でアプリ ID とパスワードを自動生成• ID とパスワードはあとで使うので、メモ帳などに貼り付け

52

Page 53: Skype for Business + Bot + Graph API

Bot 登録手順 (6/8)

管理者のメールアドレスを入力して、登録

53

Page 54: Skype for Business + Bot + Graph API

Bot 登録手順 (7/8)

Visual Studio に戻って、web.config を編集• AppID, Password を入力•最後にもう一度デプロイして、config を反映させる

54

Page 55: Skype for Business + Bot + Graph API

Bot 登録手順 (8/8)

My bot 画面の [Test] で動作確認

55

Page 56: Skype for Business + Bot + Graph API

おまけ 3Skype for Business の Channel 登録手順

56

Page 57: Skype for Business + Bot + Graph API

Channel 登録手順

「Preview だから」ということもあってか・・・

登録手順がちょっと面倒

時間がかかる(テナントの設定反映 8時間!)

57

Page 58: Skype for Business + Bot + Graph API

Channel 登録手順 (1/7)

My bot の [Add a channel] でSkype for Business を選択

58

Page 59: Skype for Business + Bot + Graph API

Channel 登録手順 (2/7)

[Learn how] をクリック

59

Page 60: Skype for Business + Bot + Graph API

Channel 登録手順 (3/7)

あとは、このページの通り

60

Page 61: Skype for Business + Bot + Graph API

Channel 登録手順 (4/7)

PowerShell の Skype for Business Online Connector モジュールをインストール※Skype for Business Bot 登録をする PC ごとに初回の1回だけ

61

Page 62: Skype for Business + Bot + Graph API

Channel 登録手順 (5/7)

管理者権限で PowerShell を開いて以下のコマンドで、Office 365 の管理者でサインイン

62

Page 63: Skype for Business + Bot + Graph API

Channel 登録手順 (6/7)

AppId を使ってエンドポイントを追加•結果が返るまで 2~3分かかることも・・・

63

Page 64: Skype for Business + Bot + Graph API

Channel 登録手順 (7/7)

あとは、ただ 8時間以上待つだけ・・・•テナントへの反映が済むまではエラーメッセージが表示される

•あきらめて Bot 削除しないように

64

Page 65: Skype for Business + Bot + Graph API

AuthBot の使い方 (1/4)

https://github.com/microsoftdx/AuthBot

65

Page 66: Skype for Business + Bot + Graph API

AuthBot の使い方 (2/4)

web.config にキー 7個を追加

66

Page 67: Skype for Business + Bot + Graph API

AuthBot の使い方 (3/4)

IDialog 実装クラス 1か所目

67

Page 68: Skype for Business + Bot + Graph API

AuthBot の使い方 (4/4)

IDialog 実装クラス 2か所目

68

Page 69: Skype for Business + Bot + Graph API

おまけ 5Azure AD 認証のローカルデバッグ方法

69

Page 70: Skype for Business + Bot + Graph API

AAD ローカルデバッグ

Azure AD 認証するアプリをローカルの IIS でデバッグするためには、

SSL を有効

にする必要があります

70

Page 71: Skype for Business + Bot + Graph API

AAD ローカルデバッグ方法 (1/3)

プロジェクトを選択して、プロパティペインで[SSL 有効] を “True” にする•ポート番号が自動的に決まるのでメモ

71

Page 72: Skype for Business + Bot + Graph API

AAD ローカルデバッグ方法 (2/3)

プロジェクトのプロパティ – [Web] で[プロジェクトの URL] に先ほど決まった URL を指定

72

Page 73: Skype for Business + Bot + Graph API

AAD ローカルデバッグ方法 (3/3)

F5 キーで Bot を起動すると、指定のポートでSSL 有効な状態で起動• PC ごとに初めての SSL 有効化の際には、証明書インストールを求められる

73