Example 3 - Use Bing Search as a fallback in Power Virtual Agents

You can enhance your bot by developing custom dialogs with Bot Framework Composer and then adding them to your Power Virtual Agents bot.

In this example, you'll learn how to set Bing search as a fallback answer in Power Virtual Agents by using Composer.

Before you begin, ensure you read Extend your bot with Bot Framework Composer to understand how Composer integrates with Power Virtual Agents.

Important

Bot Framework Composer integration is not available to users who only have the Teams Power Virtual Agents license. You must have a trial or full Power Virtual Agents license.

Prerequisites

Use Bing Search as a fallback

Open the Power Virtual Agents bot used in the previous examples.

On the left-hand menu, select Topics. Select the down-arrow symbol next to + New topic, and then select Open in Bot Framework Composer.

Select + Add new trigger to add another Bot Framework trigger to Contoso Meal Delivery Service dialog. Choose the type Unknown intent for your new trigger.

Composer - add Unknown Intent trigger.

After the Unknown intent trigger is added, go to the Bot Responses tab for this Contoso Meal Delivery Service dialog. Switch to Show code view, and insert the following Adaptive Card JSON:


# adaptivecardjson_BingSearch(user_utterance)
- ```
{    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.2",
    "fallbackText": "This card requires Media to be viewed. Ask your platform to update to Adaptive Cards v1.1 for this and more!",
    "actions": [
        {
            "type": "Action.OpenUrl",
            "title": "Search with Bing",
            "url": "https://www.bing.com/search?q=${user_utterance}",
            "style": "positive"
        }
    ],
    "body": [
        {
            "type": "Image",
            "url": "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RWe65Z?ver=2d4e&q=90&m=6&h=201&w=358&b=%23FFFFFFFF&l=f&o=t&aim=true"
        },
        {
            "type": "TextBlock",
            "text": "${user_utterance}",
            "wrap": true,
            "separator": true,
            "horizontalAlignment": "Center",
            "size": "Medium"
            
        }
    ]
}
```

Composer Bot Responses - add JSON.

Add this Activity to the same Bot Responses window in Composer:

# AdaptiveCardBingSearch(user_utterance)
[Activity
    Attachments = ${json(adaptivecardjson_BingSearch(user_utterance))}
]

Composer Bot Responses - add Activity.

Go to the Create tab in Composer and select the Unknown intent trigger. Add the Send a response action and select Show code. Add the following expression to the Bot response pane:

-${AdaptiveCardBingSearch(turn.activity.text)}

Composer BeginDialog - Send a response.

You are now ready to add your Composer content to your Power Virtual Agents bot. Go to the Publish tab in Composer and publish it to your Power Virtual Agents bot.

Once your new Composer content is successfully published, you can now see that OnUnknownIntent was added to the Topics page in Power Virtual Agents.

Note

You might need to refresh your Topics page to see the new bot content that has been added from Composer.

Power Virtual Agents Topics page for example 3.

Make sure Track between topics is turned on, and test your new bot content by entering the following text in the Test bot pane in Power Virtual Agents to start a bot conversation:

  • Is tofu vegan?

Power Virtual Agents test for example 3.

Important

Selecting Publish in Composer makes the changes available for testing, but does not automatically Publish your Power Virtual Agents bot.

Use the Publish feature in Power Virtual Agents to publish your bot changes to channels.