Skip to content

Commit 0ae142d

Browse files
Merge branch 'master' into mm-bot-enhanced-dl-oauth
2 parents ee65032 + 7d9e41b commit 0ae142d

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

articles/bot-service-channel-directline-extension-net-bot.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ This section describes how to enable the Direct Line app service extension using
7373

7474
![App service extension keys](./media/channels/direct-line-extension-extension-keys.png)
7575

76-
1. From the left panel menu under *Application settings* section, click the **Configuration** item.
76+
1. Navigate to the home page, click the **App Services** icon at the top of the page. You can also display the portal menu, and then click the **App Services** menu item, in the left panel. The App Services page is displayed.
77+
1. In the search box enter your **Web App Bot** resource name. Your resource will be listed.
78+
Notice that if you mouseover the icon or the menu item, you get the list of the last resources you viewed. Chances are your **Web App Bot** resource will be listed.
79+
1. Click your resource link.
80+
1. In the **Settings** section, click the **Configuration** menu item.
7781
1. In the right panel, add the following new settings:
7882

7983
|Name|Value|
@@ -117,7 +121,7 @@ If everything is correct, the page will return this JSON content: `{"v":"123","k
117121
- If the *initialized* value of the **.bot endpoint** is false it means the Direct Line app service extension is unable to validate the **App Service Extension Key** added to the bot's *Application Settings* above.
118122
1. Confirm the value was correctly entered.
119123
1. Switch to the alternative **App Service Extension Key** shown on your bot's **Direct Line channel configuration page**.
120-
124+
121125
- If attempting to use OAuth with the Direct Line App Service Extension and encountering the error "Unable to get the bot AppId from the audience claim." a *ClaimsIdentity* with the *AudienceClaim* assigned needs to be set on the *BotFrameworkHttpAdapter*. In order to accomplish this a developer may subclass the adapter similar to the example below:
122126

123127
```csharp

articles/v4sdk/bot-builder-howto-proactive-message.md

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ monikerRange: 'azure-bot-service-4.0'
1515

1616
[!INCLUDE [applies-to-v4](../includes/applies-to-v4-current.md)]
1717

18-
Typically, each message that a bot sends to the user directly relates to the user's prior input.
19-
In some cases, a bot may need to send the user a message that is not directly related to the current topic of conversation or to the last message the user sent. These types of messages are called _proactive messages_.
18+
Typically, a bot sends a message to a user directly in response to receiving a message from the user.
19+
Occasionally, a bot might need to send a _proactive message_, a message in response to stimulus not originating from the user.
2020

2121
Proactive messages can be useful in a variety of scenarios. For example, if the user has previously asked the bot to monitor the price of a product, the bot can alert the user if the price of the product has dropped by 20%. Or, if a bot requires some time to compile a response to the user's question, it may inform the user of the delay and allow the conversation to continue in the meantime. When the bot finishes compiling the response to the question, it will share that information with the user.
2222

@@ -38,7 +38,27 @@ More information about proactive messages in Teams can be found in these resourc
3838

3939
## About the proactive sample
4040

41-
The sample has a bot and an additional controller that is used to send proactive messages to the bot, as shown in the following illustration.
41+
In general, a bot as an application has a few layers:
42+
43+
- The web application that can accept HTTP requests and specifically supports a messaging endpoint.
44+
- An adapter that handles connectivity with the channels.
45+
- A handler for the turn, typically encapsulated in a _bot_ class that handles the conversational reasoning for the bot app.
46+
47+
In response to an incoming message from the user, the app calls the adapter's _process activity_ method, which creates a turn and turn context, calls its middleware pipeline, and then calls the bot's turn handler.
48+
49+
To initiate a proactive message, the bot application needs to be able to receive additional input.
50+
The application logic for initiating a proactive message is outside the scope of the SDK.
51+
For this sample, a _notify_ endpoint, in addition to a standard _messages_ endpoint, is used to trigger the proactive turn.
52+
53+
In response to a GET request on this notify endpoint, the app calls the adapter's _continue conversation_ method, which behaves similarly to the the _process activity_ method. The _continue conversation_ method:
54+
55+
- Takes an appropriate conversation reference for the user and the callback method to use for the proactive turn.
56+
- Creates an event activity and turn context for the proactive turn.
57+
- Calls the adapter's middleware pipeline.
58+
- Calls the provided callback method.
59+
- The turn context uses the conversation reference to send any messages to the user.
60+
61+
The sample has a bot, a messages endpoint, and an additional notify endpoint that is used to send proactive messages to the user, as shown in the following illustration.
4262

4363
![proactive bot](media/proactive-sample-bot.png)
4464

@@ -76,11 +96,11 @@ The conversation reference includes a _conversation_ property that describes the
7696
7797
## Send proactive message
7898

79-
The second controller, the _notify_ controller, is responsible for sending the proactive message to the bot. It uses the following steps to generate a proactive message.
99+
The second controller, the _notify_ controller, is responsible for sending the proactive message to the user. It uses the following steps to generate a proactive message.
80100

81101
1. Retrieves the reference for the conversation to which to send the proactive message.
82102
1. Calls the adapter's _continue conversation_ method, providing the conversation reference and the turn handler delegate to use. (The continue conversation method generates a turn context for the referenced conversation and then calls the specified turn handler delegate.)
83-
1. In the delegate, uses the turn context to send the proactive message.
103+
1. In the delegate, uses the turn context to send the proactive message. Here, the delegate is defined on the notify controller, and it sends the proactive message to the user.
84104

85105
> [!NOTE]
86106
> While each channel should use a stable service URL, the URL can change over time. For more information about the service URL, see the [Basic activity structure](https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-activity.md#basic-activity-structure) and [Service URL](https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-activity.md#service-url) sections of the Bot Framework Activity Schema.
@@ -136,43 +156,25 @@ An ad hoc proactive message is the simplest type of proactive message. The bot s
136156

137157
To handle notifications more smoothly, consider other ways to integrate the notification into the conversation flow, such as setting a flag in the conversation state or adding the notification to a queue.
138158

139-
### Avoiding 401 "Unauthorized" Errors
140-
141-
By default, the Bot Builder SDK adds a `serviceUrl` to the list of trusted host names if the incoming request is authenticated by BotAuthentication. They are maintained in an in-memory cache. If your bot is restarted, a user awaiting a proactive message cannot receive it unless they have messaged the bot again after it restarted.
159+
### About the proactive turn
142160

143-
To avoid this, you must manually add the `serviceUrl` to the list of trusted host names.
161+
The _continue conversation_ method uses the conversation reference and a turn callback handler to:
144162

145-
# [C#](#tab/csharp)
163+
1. Create a turn in which the bot application can send the proactive message. The adapter creates an `event` activity for this turn, with its name set to "ContinueConversation".
164+
1. Send the turn through the adapter's middleware pipeline.
165+
1. Call the turn callback handler to perform custom logic.
146166

147-
```csharp
148-
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);
149-
```
167+
In the **proactive messages** sample, the turn callback handler is defined in the notify controller and sends the message directly to the conversation, without sending the proactive activity through the bot's normal turn handler.
168+
The sample code also does not access or update the bot's state on the proactive turn.
150169

151-
For proactive messaging, `serviceUrl` is the URL of the channel that the recipient of the proactive message is using and can be found in `Activity.ServiceUrl`.
170+
Many bots are stateful and use state to manage a conversation over multiple turns.
171+
When the continue conversation method creates a turn context, the turn will have the correct user and conversation state associated with it, and you can integrate proactive turns into your bot's logic.
172+
If you need the bot logic to be aware of the proactive message, you have a few options for doing so. You can:
152173

153-
You'll want to add the above code just prior to the the code that sends the proactive message. In the [Proactive Messages Sample](https://aka.ms/proactive-sample-cs), you would put it in `NotifyController.cs` just before `await turnContext.SendActivityAsync("proactive hello");`.
154-
155-
# [JavaScript](#tab/javascript)
174+
- Provide the bot's turn handler as the turn callback handler. The bot will then receive the "ContinueConversation" event activity.
175+
- Use the turn callback handler to add information to the turn context first, and then call the bot's turn handler.
156176

157-
```js
158-
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
159-
```
160-
161-
For proactive messaging, `serviceUrl` is the URL of the channel that the recipient of the proactive message is using and can be found in `activity.serviceUrl`.
162-
163-
You'll want to add the above code just prior to the the code that sends the proactive message. In the [Proactive Messages Sample](https://aka.ms/proactive-sample-js), you would put it in `index.js` just before `await turnContext.sendActivity('proactive hello');`.
164-
165-
# [Python](#tab/python)
166-
167-
```python
168-
MicrosoftAppCredentials.trustServiceUrl(serviceUrl)
169-
```
170-
171-
For proactive messaging, `serviceUrl` is the URL of the channel that the recipient of the proactive message is using and can be found in `activity.serviceUrl`.
172-
173-
You'll want to add the above code just prior to the the code that sends the proactive message. In the [Proactive Messages Sample](https://aka.ms/bot-proactive-python-sample-code), you add it in `app.py` prior sending the *proactive hello* message.
174-
175-
---
177+
In both of these cases, you will need to design your bot logic to handle the proactive event.
176178

177179
## Next steps
178180

0 commit comments

Comments
 (0)