问题
We are trying to send a message into our bot using the direct line api and then send a message out from our bot without using the direct line api. In order to do this, we need a different service url than the default direct line api service url.
We have tried putting a different service url in the activity we send the direct line api but then when the activity is sent to the bot the direct line api service url is populated instead.
We have also tried changing the service url in the activity once it has been sent to the bot, but the bot still tries to send its response activity to the direct line api.
The only way we have gotten this to work is to do the following:
((Microsoft.Bot.Connector.IConnectorClient)turnContext.TurnState["Microsoft.Bot.Connector.IConnectorClient"]).BaseUri = new System.Uri("DIFFERENT_SERCVICE_URL");
Although this works, we don't think it is the best way to solve this problem and we probably should not be modifying the turn state.
Is there a better way to change this service url?
回答1:
There are at least three levels at which your bot can send an activity to the user. TurnContext.SendActivities
calls BotAdapter.SendActivitiesAsync
, and if you're using a BotFrameworkAdapter
then that in turn calls Conversations.SendToConversationAsync
using the connector client stored in turn state. All three of these method families are available to your bot, so if you want to bypass the turn context then you can use the adapter directly and if you want to bypass the adapter then you can use the connector client directly.
You've discovered that your activities get sent to the base URI of the connector client when you try to send activities using the turn context. If you don't want to modify the connector client in the turn state then you can create a different connector client and use that instead.
来源:https://stackoverflow.com/questions/62881626/changing-the-service-url-for-a-direct-line-activity-that-is-sent-to-our-bot