BotFrameworkAdapter 類別
定義將 Bot 連線至服務端點的配接器。
初始化 BotFrameworkAdapter 類別的新實例。
建構函式
BotFrameworkAdapter(settings: BotFrameworkAdapterSettings)
參數
| 名稱 | Description |
|---|---|
|
settings
必要
|
初始化配接器的設定 |
備註
Bot 配接器會封裝驗證程式,並將活動傳送至 Bot Connector Service 並從中接收活動。 當 Bot 收到活動時,配接器會建立內容物件、將它傳遞給 Bot 的應用程式邏輯,並將回應傳回使用者的通道。 配接器會透過 Bot 中間件管線將傳入的活動處理並導向至 Bot 的邏輯,然後再次返回。 當每個活動進出 Bot 時,每個中間件都可以在 Bot 邏輯執行前後檢查或處理活動。
方法
| can_process_outgoing_activity | |
| continue_conversation |
繼續與使用者交談。 和 通常會在 config.py的 MicrosoftAppId 參數中找到。 :type bot_id: <xref:typing.str> :p aram claims_identity: Bot 宣告身分識別 :type claims_identity: <xref:botframework.connector.auth.ClaimsIdentity> :p aram 物件: :類型物件: <xref:typing.str> |
| create_connector_client |
實作ConnectorClientProvider.create_connector_client。 |
| create_conversation |
開始與使用者的新交談。 用來將訊息導向群組的成員。 |
| delete_activity |
刪除先前傳送至通道的活動。 請注意,並非所有通道都支援這項功能。 注意 ConversationReference 的activity_id會識別要刪除的活動。 |
| delete_conversation_member |
從目前的交談中刪除成員。 |
| exchange_token | |
| exchange_token_from_credentials | |
| get_aad_tokens |
擷取已設定連線上特定資源的 Azure Active Directory 令牌。 從 TurnContext 中的 Activity。 :type user_id: str :p aram oauth_app_credentials: (選擇性) 適用於 OAuth 的 AppCredentials。 :type oauth_app_credentials:<xref:botframework.connector.auth.AppCredential> |
| get_activity_members |
列出指定活動的成員。 如果未指定,則會使用目前的活動標識符。 |
| get_conversation_member |
擷取目前交談的成員。 |
| get_conversation_members |
列出目前交談的成員。 |
| get_conversations |
列出此 Bot 參與指定通道伺服器的交談。 context.activity.serviceUrl :type service_url: str |
| get_oauth_sign_in_link |
取得要傳送給使用者以進行連線名稱登入的原始登入連結。 |
| get_sign_in_resource_from_user | |
| get_sign_in_resource_from_user_and_credentials | |
| get_token_status |
擷取指定使用者每個已設定連線的令牌狀態。 空白會傳回所有已設定連線的令牌狀態。 :type include_filter: str :p aram oauth_app_credentials: (選擇性) 適用於 OAuth 的 AppCredentials。 :type oauth_app_credentials:<xref:botframework.connector.auth.AppCredential> |
| get_user_token |
嘗試擷取登入流程中之使用者的令牌。 :p aram magic_code“ (選擇性) 使用者輸入程式代碼來驗證 :str magic_code” str :p aram oauth_app_credentials: (選擇性) AppCredentials for OAuth。 :type oauth_app_credentials:<xref:botframework.connector.auth.AppCredential> |
| key_for_app_credentials | |
| key_for_connector_client | |
| parse_request |
剖析和驗證要求:p aram req: :return: |
| process_activity |
建立回合內容,並執行傳入活動的中間件管線。 |
| process_activity_with_identity | |
| process_outgoing_activity | |
| send_activities | |
| sign_out_user |
使用令牌伺服器將用戶註銷。 |
| update_activity |
取代先前傳送至通道的活動。 請注意,並非所有通道都支援這項功能。 |
can_process_outgoing_activity
can_process_outgoing_activity(activity: Activity) -> bool
參數
| 名稱 | Description |
|---|---|
|
activity
必要
|
|
continue_conversation
繼續與使用者交談。
和 通常會在 config.py的 MicrosoftAppId 參數中找到。 :type bot_id: <xref:typing.str> :p aram claims_identity: Bot 宣告身分識別 :type claims_identity: <xref:botframework.connector.auth.ClaimsIdentity> :p aram 物件: :類型物件: <xref:typing.str>
async continue_conversation(reference: ConversationReference, callback: Callable, bot_id: str = None, claims_identity: ClaimsIdentity = None, audience: str = None)
參數
| 名稱 | Description |
|---|---|
|
reference
必要
|
|
|
callback
必要
|
|
|
bot_id
|
預設值: None
|
|
claims_identity
|
預設值: None
|
|
audience
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
工作,表示要執行的工作佇列。 |
例外狀況
| 類型 | Description |
|---|---|
|
It raises an argument null exception.
|
備註
這通常稱為 Bot 主動傳訊 流程,因為它可讓 Bot 主動將訊息傳送至已處於通訊中的交談或使用者。 此函式會啟用傳送通知或優惠券給使用者的案例。
create_connector_client
實作ConnectorClientProvider.create_connector_client。
async create_connector_client(service_url: str, identity: ClaimsIdentity = None, audience: str = None) -> ConnectorClient
參數
| 名稱 | Description |
|---|---|
|
service_url
必要
|
服務 URL |
|
identity
|
宣告身分識別 預設值: None
|
|
audience
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
<xref:botbuilder.core.ConnectorClient> 類別的實例 |
create_conversation
開始與使用者的新交談。 用來將訊息導向群組的成員。
async create_conversation(reference: ConversationReference, logic: Callable[[TurnContext], Awaitable] = None, conversation_parameters: ConversationParameters = None, channel_id: str = None, service_url: str = None, credentials: AppCredentials = None)
參數
| 名稱 | Description |
|---|---|
|
reference
必要
|
包含租使用者的交談參考 |
|
logic
|
用於建立交談的邏輯 預設值: None
|
|
conversation_parameters
|
用來建立交談的資訊 預設值: None
|
|
channel_id
|
<xref:typing.str>
通道的標識碼。 預設值: None
|
|
service_url
|
<xref:typing.str>
通道的服務 URL 端點。 預設值: None
|
|
credentials
|
<xref:botframework.connector.auth.AppCredentials>
Bot 的應用程式認證。 預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
工作,表示要執行的工作佇列。 |
例外狀況
| 類型 | Description |
|---|---|
|
It raises a generic exception error.
|
備註
若要開始交談,您的 Bot 必須知道其帳戶資訊和該通道上的用戶帳戶資訊。 大部分的通道都只支援起始直接訊息(非群組)交談。 配接器會嘗試在通道上建立新的交談,然後透過其中間件管線將交談更新活動傳送至回呼方法。 如果與指定的使用者建立交談,活動的標識碼將會包含新交談的標識碼。
delete_activity
刪除先前傳送至通道的活動。 請注意,並非所有通道都支援這項功能。
注意
ConversationReference 的activity_id會識別要刪除的活動。
async delete_activity(context: TurnContext, reference: ConversationReference)
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
回合的內容物件 |
|
reference
必要
|
要刪除之活動的交談參考 |
傳回
| 類型 | Description |
|---|---|
|
工作,表示要執行的工作排入佇列 |
例外狀況
| 類型 | Description |
|---|---|
|
A exception error
|
delete_conversation_member
從目前的交談中刪除成員。
async delete_conversation_member(context: TurnContext, member_id: str) -> None
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
回合的內容物件 |
|
member_id
必要
|
要從交談中移除的成員標識碼 |
傳回
| 類型 | Description |
|---|---|
|
工作,表示要執行的工作佇列。</returns |
例外狀況
| 類型 | Description |
|---|---|
|
A exception error
|
exchange_token
async exchange_token(turn_context: TurnContext, connection_name: str, user_id: str, exchange_request: TokenExchangeRequest) -> TokenResponse
參數
| 名稱 | Description |
|---|---|
|
turn_context
必要
|
|
|
connection_name
必要
|
|
|
user_id
必要
|
|
|
exchange_request
必要
|
|
exchange_token_from_credentials
async exchange_token_from_credentials(turn_context: TurnContext, oauth_app_credentials: AppCredentials, connection_name: str, user_id: str, exchange_request: TokenExchangeRequest) -> TokenResponse
參數
| 名稱 | Description |
|---|---|
|
turn_context
必要
|
|
|
oauth_app_credentials
必要
|
|
|
connection_name
必要
|
|
|
user_id
必要
|
|
|
exchange_request
必要
|
|
get_aad_tokens
擷取已設定連線上特定資源的 Azure Active Directory 令牌。
從 TurnContext 中的 Activity。 :type user_id: str :p aram oauth_app_credentials: (選擇性) 適用於 OAuth 的 AppCredentials。 :type oauth_app_credentials:<xref:botframework.connector.auth.AppCredential>
async get_aad_tokens(context: TurnContext, connection_name: str, resource_urls: List[str], user_id: str = None, oauth_app_credentials: AppCredentials = None) -> Dict[str, TokenResponse]
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
|
|
connection_name
必要
|
|
|
resource_urls
必要
|
|
|
user_id
|
預設值: None
|
|
oauth_app_credentials
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
對應 :class:'botbuilder.schema.TokenResponse' 的資源 URL 字典 |
get_activity_members
列出指定活動的成員。
如果未指定,則會使用目前的活動標識符。
async get_activity_members(context: TurnContext, activity_id: str)
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
|
|
activity_id
必要
|
|
傳回
| 類型 | Description |
|---|---|
|
活動的成員清單 |
例外狀況
| 類型 | Description |
|---|---|
|
An exception error
|
get_conversation_member
擷取目前交談的成員。
async get_conversation_member(context: TurnContext, member_id: str) -> ChannelAccount
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
回合的內容物件 |
|
member_id
必要
|
成員標識碼 |
傳回
| 類型 | Description |
|---|---|
|
目前交談的成員 |
例外狀況
| 類型 | Description |
|---|---|
|
<xref:A TypeError if missing member_id>, <xref:service_url>, <xref:or conversation.id>
|
get_conversation_members
列出目前交談的成員。
async get_conversation_members(context: TurnContext)
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
回合的內容物件 |
傳回
| 類型 | Description |
|---|---|
|
目前交談的成員清單 |
例外狀況
| 類型 | Description |
|---|---|
|
TypeError if missing service_url or conversation.id
|
get_conversations
列出此 Bot 參與指定通道伺服器的交談。
context.activity.serviceUrl :type service_url: str
async get_conversations(service_url: str, credentials: AppCredentials, continuation_token: str = None)
參數
| 名稱 | Description |
|---|---|
|
continuation_token
|
結果上一頁的接續令牌 預設值: None
|
|
service_url
必要
|
|
|
credentials
必要
|
|
傳回
| 類型 | Description |
|---|---|
|
工作,表示要執行的工作排入佇列 |
例外狀況
| 類型 | Description |
|---|---|
|
A generic exception error
|
備註
通道伺服器會傳回頁面的結果,而且每個頁面都會包含 continuationToken,可用來從伺服器擷取下一頁的結果。 如果工作順利完成,結果會包含目前交談成員的頁面。 此多載可以從交談內容外部呼叫,因為只需要 Bot 的服務 URL 和認證。
get_oauth_sign_in_link
取得要傳送給使用者以進行連線名稱登入的原始登入連結。
async get_oauth_sign_in_link(context: TurnContext, connection_name: str, final_redirect: str = None, oauth_app_credentials: AppCredentials = None) -> str
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
與使用者目前交談回合的內容 |
|
connection_name
必要
|
要使用的驗證連線名稱 |
|
final_redirect
|
OAuth 流程將重新導向至的最後URL。 預設值: None
|
|
oauth_app_credentials
|
<xref:botframework.connector.auth.AppCredential>
(選擇性)適用於 OAuth 的 AppCredentials。 預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
如果工作順利完成,結果會包含原始登入連結 |
get_sign_in_resource_from_user
async get_sign_in_resource_from_user(turn_context: TurnContext, connection_name: str, user_id: str, final_redirect: str = None) -> SignInUrlResponse
參數
| 名稱 | Description |
|---|---|
|
turn_context
必要
|
|
|
connection_name
必要
|
|
|
user_id
必要
|
|
|
final_redirect
|
預設值: None
|
get_sign_in_resource_from_user_and_credentials
async get_sign_in_resource_from_user_and_credentials(turn_context: TurnContext, oauth_app_credentials: AppCredentials, connection_name: str, user_id: str, final_redirect: str = None) -> SignInUrlResponse
參數
| 名稱 | Description |
|---|---|
|
turn_context
必要
|
|
|
oauth_app_credentials
必要
|
|
|
connection_name
必要
|
|
|
user_id
必要
|
|
|
final_redirect
|
預設值: None
|
get_token_status
擷取指定使用者每個已設定連線的令牌狀態。
空白會傳回所有已設定連線的令牌狀態。 :type include_filter: str :p aram oauth_app_credentials: (選擇性) 適用於 OAuth 的 AppCredentials。 :type oauth_app_credentials:<xref:botframework.connector.auth.AppCredential>
async get_token_status(context: TurnContext, connection_name: str = None, user_id: str = None, include_filter: str = None, oauth_app_credentials: AppCredentials = None) -> List[TokenStatus]
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
|
|
connection_name
|
預設值: None
|
|
user_id
|
預設值: None
|
|
include_filter
|
預設值: None
|
|
oauth_app_credentials
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
<xref:botframework.connector.token_api.modelsTokenStatus> 陣列 |
get_user_token
嘗試擷取登入流程中之使用者的令牌。
:p aram magic_code“ (選擇性) 使用者輸入程式代碼來驗證 :str magic_code” str :p aram oauth_app_credentials: (選擇性) AppCredentials for OAuth。 :type oauth_app_credentials:<xref:botframework.connector.auth.AppCredential>
async get_user_token(context: TurnContext, connection_name: str, magic_code: str = None, oauth_app_credentials: AppCredentials = None) -> TokenResponse
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
|
|
connection_name
必要
|
|
|
magic_code
|
預設值: None
|
|
oauth_app_credentials
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
:<xref:class>:’TokenResponse`
|
令牌回應 |
例外狀況
| 類型 | Description |
|---|---|
|
An exception error
|
key_for_app_credentials
static key_for_app_credentials(app_id: str, scope: str)
參數
| 名稱 | Description |
|---|---|
|
app_id
必要
|
|
|
scope
必要
|
|
key_for_connector_client
static key_for_connector_client(service_url: str, app_id: str, scope: str)
參數
| 名稱 | Description |
|---|---|
|
service_url
必要
|
|
|
app_id
必要
|
|
|
scope
必要
|
|
parse_request
剖析和驗證要求:p aram req: :return:
async static parse_request(req)
參數
| 名稱 | Description |
|---|---|
|
req
必要
|
|
process_activity
建立回合內容,並執行傳入活動的中間件管線。
async process_activity(req, auth_header: str, logic: Callable)
參數
| 名稱 | Description |
|---|---|
|
req
必要
|
<xref:typing.str>
傳入活動 |
|
auth_header
必要
|
<xref:typing.str>
要求的 HTTP 驗證標頭 |
|
logic
必要
|
在配接器中間件管線結尾執行的邏輯。 |
傳回
| 類型 | Description |
|---|---|
|
工作,表示要執行的工作佇列。 |
備註
此類別會處理 Bot 網頁伺服器所接收的活動。 這包括從用戶傳送的任何訊息,也是驅動通常稱為 Bot 的方法,回應式傳訊 流程。 呼叫此方法,以回應方式將訊息傳送至交談。 如果工作順利完成,則會傳回 InvokeResponse;否則。 傳回 null。
process_activity_with_identity
async process_activity_with_identity(activity: Activity, identity: ClaimsIdentity, logic: Callable)
參數
| 名稱 | Description |
|---|---|
|
activity
必要
|
|
|
identity
必要
|
|
|
logic
必要
|
|
process_outgoing_activity
async process_outgoing_activity(turn_context: TurnContext, activity: Activity) -> ResourceResponse
參數
| 名稱 | Description |
|---|---|
|
turn_context
必要
|
|
|
activity
必要
|
|
send_activities
async send_activities(context: TurnContext, activities: List[Activity]) -> List[ResourceResponse]
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
|
|
activities
必要
|
|
sign_out_user
使用令牌伺服器將用戶註銷。
async sign_out_user(context: TurnContext, connection_name: str = None, user_id: str = None, oauth_app_credentials: AppCredentials = None)
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
與使用者目前交談回合的內容 |
|
connection_name
|
要使用的驗證連線名稱 預設值: None
|
|
user_id
|
要註銷的使用者標識碼 預設值: None
|
|
oauth_app_credentials
|
<xref:botframework.connector.auth.AppCredential>
(選擇性)適用於 OAuth 的 AppCredentials。 預設值: None
|
update_activity
取代先前傳送至通道的活動。 請注意,並非所有通道都支援這項功能。
async update_activity(context: TurnContext, activity: Activity)
參數
| 名稱 | Description |
|---|---|
|
context
必要
|
回合的內容物件 |
|
activity
必要
|
新的取代活動 |
傳回
| 類型 | Description |
|---|---|
|
工作,表示要執行的工作排入佇列 |
例外狀況
| 類型 | Description |
|---|---|
|
A generic exception error
|
備註
如果成功傳送活動,工作結果會包含 ResourceResponse 物件,其中包含指派給活動的接收通道標識碼。 呼叫此函式之前,請將取代活動的標識碼設定為要取代之活動的標識碼。