Teams Bot開發系列:Activity和Turn

這篇文章我們來說一下Activity和Turn這兩個bot framework中最重要的兩個概念,同時也介紹一下TurnContext和BotAdapter

Activity

一個activity是聊天雙方的一個信息載體,它可以是一條消息,也可以是一個動作。比如用戶給bot發送一條文字消息,這就是一個activity,bot給用戶回復一張圖片,那這是另一個activity。

Activity是bot framework里最重要的概念,讓我們來一起看一下c# sdk里對activity的定義。真實感受一下

    public class Activity{public string Type { get; set; }public string Id { get; set; }public DateTimeOffset? Timestamp { get; set; }public DateTimeOffset? LocalTimestamp { get; set; }public string LocalTimezone { get; set; }public string ServiceUrl { get; set; }public string ChannelId { get; set; }public ChannelAccount From { get; set; }public ConversationAccount Conversation { get; set; }public ChannelAccount Recipient { get; set; }public string TextFormat { get; set; }public string AttachmentLayout { get; set; }public IList<ChannelAccount> MembersAdded { get; set; }public IList<ChannelAccount> MembersRemoved { get; set; }public IList<MessageReaction> ReactionsAdded { get; set; }public IList<MessageReaction> ReactionsRemoved { get; set; }public string TopicName { get; set; }public bool? HistoryDisclosed { get; set; }public string Locale { get; set; }public string Text { get; set; }public string Speak { get; set; }public string InputHint { get; set; }public string Summary { get; set; }public SuggestedActions SuggestedActions { get; set; }public IList<Attachment> Attachments { get; set; }public IList<Entity> Entities { get; set; }public object ChannelData { get; set; }public string Action { get; set; }public string ReplyToId { get; set; }public string Label { get; set; }public string ValueType { get; set; }public object Value { get; set; }public string Name { get; set; }public ConversationReference RelatesTo { get; set; }public string Code { get; set; }public DateTimeOffset? Expiration { get; set; }public string Importance { get; set; }public string DeliveryMode { get; set; }public IList<string> ListenFor { get; set; }public IList<TextHighlight> TextHighlights { get; set; }public SemanticAction SemanticAction { get; set; }public string CallerId { get; set; }}

除了上面這么多的屬性,還有很多方法和擴展方法,是一個非常大的類,我們以后詳細一一說明。

Turn

下面是對于turn的官方說明:

In a conversation, people often speak one-at-a-time, taking turns speaking. With a bot, it generally reacts to user input. Within the Bot Framework SDK, a turn consists of the user’s incoming activity to the bot and any activity the bot sends back to the user as an immediate response. You can think of a turn as the processing associated with the arrival of a given activity.

一個turn就是對一個activity的相關處理。比如說,對于用戶發給我們bot一條消息,我們把這條消息轉發給另一個用戶,同時對消息本身點贊,那這兩個操作一起是一個turn,是針對用戶發來的消息的處理的turn。

Turn上下文(Turn Context)

我認為TurnContext是僅次于Activity的概念,turn context對象跟隨著整個消息的處理過程。地位非常類似以前asp.net的HttpContext概念。

    public interface ITurnContext{BotAdapter Adapter { get; }TurnContextStateCollection TurnState { get; }Activity Activity { get; }bool Responded { get; }Task<ResourceResponse> SendActivityAsync(...);Task<ResourceResponse> UpdateActivityAsync(...);Task DeleteActivityAsync(...);ITurnContext OnSendActivities(...);ITurnContext OnUpdateActivity(...);ITurnContext OnDeleteActivity(...);}

可以看到TurnContext不算龐大,其他的屬性和方法看名字比較容易理解。其中一個主要概念是BotAdapter

BotAdapter

從官方說明,我們可以看到這個是鏈接你bot endpoint和bot處理邏輯的一個橋梁,它封裝了對于安全驗證和對middleware的處理。當你的bot endpoint收到一個請求時,BotAdapter會驗證這個請求是不是從正式渠道發送來的請求,如果是,它會創建Turn Context,然后開始各個middleware的處理。

要注意的一點是:Activity是貫穿于Azure bot service和bot framework sdk整條pipeline的,但是turn,turn context和BotAdapter,目前版本(v4)只是存在于bot framework sdk,是幫助開發人員處理bot的一個東西,如果你不想用turn,想自己處理整個bot的聊天,你可以只使用?Microsoft.Bot.Schema(包含Activity定義),不添加Microsoft.Bot.Builder庫(含有turncontext和BotAdapter定義)。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/277942.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/277942.shtml
英文地址,請注明出處:http://en.pswp.cn/news/277942.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ubuntu16.04下安裝opencv出現libgtk2.0-dev配置失敗問題解決方法

第一次在ubuntu下安裝opencv&#xff0c;遇到很多問題&#xff0c;特別是libgtk2.0-dev總是配置失敗的問題&#xff0c;在網上也看到一些解決方法&#xff0c;自己也遇到一些比較奇葩的問題&#xff0c;故整理于此。 網上大部分的解決方案就是更改下載源&#xff0c;我看到一些…

03|模型I/O:輸入提示、調用模型、解析輸出

03&#xff5c;模型I/O&#xff1a;輸入提示、調用模型、解析輸出 從這節課開始&#xff0c;我們將對 LangChain 中的六大核心組件一一進行詳細的剖析。 模型&#xff0c;位于 LangChain 框架的最底層&#xff0c;它是基于語言模型構建的應用的核心元素&#xff0c;因為所謂 …

selenuim自動化爬取汽車在線谷米愛車網車輛GPS數據爬蟲

#為了實時獲取車輛信息&#xff0c;以及為了后面進行行使軌跡繪圖&#xff0c;寫了一個基于selelnium的爬蟲爬取了車輛gps數據。 #在這里發現selenium可以很好的實現網頁解析和處理js處理 #導包 import timefrom selenium import webdriverfrom selenium.webdriver.support.wai…

Teams Bot開發系列:Activity處理流程

上篇文章介紹了什么是Activity&#xff0c;Turn&#xff0c;TurnContext和BotAdapter&#xff0c;這篇文章我們看看這些東西是如何竄起來的&#xff0c;他們是如何處理用戶發給bot的消息的。 我們以一個最簡單的bot&#xff0c;echo bot為例子&#xff0c;所謂的echo bot就是用…

寫單元測試的好處(轉)

許多開發者都有個習慣&#xff0c;常常不樂意去寫個簡單的單元測試程序來驗證自己的代碼。對自己的程序一直非常有自信&#xff0c;或存在僥幸心理每次運行通過后就直接扔給測試組測試了。然而每次測試組的BUG提交過來后就會發現自己的程序還存在許多沒有想到的漏洞。但是每次修…

linux下搭建go環境--問題記錄

記錄自己在linux上搭建go環境的經歷。&#xff08;因為各種版本&#xff0c;linux系統問題掙扎了幾天&#xff09; 安裝vmware-tools,把我要運行代碼拷進來。這個網上方法很多&#xff0c;我的電腦抽風不能安裝&#xff0c;后面重裝的虛擬機確定Ubuntu版本、位數。很重要&#…

Teams Bot開發系列:Teams的Activity處理

上一篇文章講了activity處理的流程&#xff0c;我們bot的核心處理邏輯放在ActivityHandler的子類里&#xff0c;通過重載OnMessageActivityAsync()方法來實現。 這篇文章我來講一下對于Teams的bot來說&#xff0c;整個處理的邏輯會有哪些不同點。 通過之前的文章&#xff0c;…

取球博弈

兩個人玩取球的游戲。一共有N個球&#xff0c;每人輪流取球&#xff0c;每次可取集合{n1,n2,n3}中的任何一個數目。 如果無法繼續取球&#xff0c;則游戲結束。 此時&#xff0c;持有奇數個球的一方獲勝。 如果兩人都是奇數&#xff0c;則為平局。 假設雙方都采用最聰明的取法…

MySQL修改字符集

MySQL數據庫修改字符集,介紹一下修改的方法 1&#xff09;系統工具iconv #file filename #mysqldump --default-character-setutf8 >20180523xxx.sql #file 20180523xxx.sql #iconv -t utf8mb4 -c 20180523xxx.sql>20180523xxxutf8mb4.sql #file 20180523xxxutf8mb4.sql…

Teams Bot開發系列:Bot驗證

我們今天來說一下authentication&#xff0c;authentication一直是一個復雜的問題。bot里的authentication也不簡單。我們先來看一個概念&#xff1a;Bot Framework Token Service&#xff0c;根據官方定義&#xff0c;這個token service主要是&#xff1a; Facilitating the u…

堆排序

目錄 一、定義二、算法分析三、代碼地址一、定義 1.1 堆 ? 此處的堆&#xff0c;指數據結構中的堆。而不是內存中的那種內存堆&#xff0c;內存堆是基于數據結構的一種實現。堆的數據結構是一棵完全二叉樹&#xff0c;它有如下特點&#xff1a;&#xff08;具體參考下文鏈接&a…

Teams Bot開發系列:Middleware

middleware是目前一些framework比較流行的概念&#xff0c;通常一個開發框架需要提供一些可擴展可定制化的功能。所以middleware這種pattern就很實用。 熟悉asp.net core的開發可能第一個想到的就是asp.net core的middleware&#xff0c;如下圖&#xff1a; 當一個http reques…

如何獲取租戶中所有的Team

大家在使用Graph API開發Teams App的時候&#xff0c;有時候會需要獲取某個租戶Tenant的所有team&#xff0c;在寫這篇文章的時候Graph API并沒有提供這么一個功能&#xff0c;沒有一個類似于”GET /teams”的api。 在Micorsoft Graph官方文檔的已知問題中&#xff0c;也提到了…

mysql常用快速查詢修改操作

mysql常用快速查詢修改操作 一、查找并修改非innodb引擎為innodb引擎 # 通用操作 mysql> select concat(alter table ,table_schema,.,table_name, engineinnodb;) from information_schema.tables where table_schema not in (information_schema,mysql,performance_schem…

ElasticSearch教程——自定義分詞器(轉學習使用)

一、分詞器 Elasticsearch中&#xff0c;內置了很多分詞器&#xff08;analyzers&#xff09;&#xff0c;例如standard&#xff08;標準分詞器&#xff09;、english&#xff08;英文分詞&#xff09;和chinese&#xff08;中文分詞&#xff09;&#xff0c;默認是standard. s…

使用Azure Serverless來開發Teams App

Azure Function可以說比較早期的一個serverless服務&#xff0c;隨著這些年云服務的大行其道&#xff0c;Serverless在概念越來越火&#xff0c;什么叫serverless&#xff1f; Serverless computing (or serverless for short), is an execution model where the cloud provide…

Angular之RouterModule的forRoot與forChild

Angular 提供了一種方式來把服務提供商從模塊中分離出來&#xff0c;以便模塊既可以帶著 providers 被根模塊導入&#xff0c;也可以不帶 providers 被子模塊導入。 區別&#xff1a; forRoot creates a module that contains all the directives, the given routes, and the r…

關于 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh的解決辦法

關于 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh的解決辦法 記錄工作中遇到的問題 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh  由于遠程機器或者重組或者更新了ssh server導致本地記錄的驗證信…

使用AzureFunction開發最簡單的Teams Outgoing Webhook

上篇文章講了teams app的serverless架構&#xff0c;這篇主要講如何真正使用Azure Function來開發一個最最簡單的Teams Outgoing Webhook。 我們先登入azure的portal&#xff0c;創建一個azure function。我這里創建了一個名字叫outgoing-webhook的azure function。完成后如下…

Java 基礎 之 標識符

www.verejava.com/?id1699254… /* 標識符的命名規則: 1. 是以字母&#xff0c;數字&#xff0c;下滑線_和美元符號$ 組成 2. 不能以數字開頭 3. 區分大小寫 4. 不能是java的保留關鍵字 5. 最好是見名思意 */ public class Identifier {public static void main(String[] args…