I currently have a fully functioning Virtual Assistant Template-based chatbot with a skill attached to it. My goal is for the skill to work as a search function that can find resources in a CosmosDB and pull them back for the user to use. After doing some research I believe the best way to do this would be to use Azure search to retrieve said info. From what I've seen in the Virtual Assistant Template documentation integration with Azure Search should definitely be possible... I just haven't found any examples or tutorials on how to do so. If anyone knows how to create an azure search resource and integrate it into a bot, or knows of a resource that tells you how to do so, please let me know!
For your scenario, an outline of what to do is:
Create an Azure search service
In that create an indexer that will point to your Cosmos DB data source. Here is documentation specific to how you can crawl through your data in Cosmos DB: https://learn.microsoft.com/en-us/azure/search/search-howto-index-cosmosdb
Once your indexer runs and has crawled through your data, it should be available for searching, from the app in your search index.
There isn't an end to end tutorial about integrating with a bot, but here is an Azure search tutorial that shows an complete scenario of crawling through a SQL database and then searching using full-text search.
https://learn.microsoft.com/en-us/azure/search/search-indexer-tutorial
You should be able to follow most of the guidance there, except replace the parts about SQL indexer with details from Cosmos DB indexer in the link above.
I want to do a similar search (only in AzureBlob instead of Cosmos DB). I am using sdk v4 for my bot framework and Visual Studio 2019. I'm trying to call the service through the code below:
public ISearchIndexClient CreateSearchIndexClient()
{
string searchServiceName = "MySearchServiceName";
string queryApiKey = "MySearchServiceKey";
string indexName = "MyIndexName";
SearchIndexClient indexClient = new SearchIndexClient(searchServiceName, indexName, new SearchCredentials(queryApiKey));
return indexClient;
}
public async Task StartAsync(ITurnContext turnContext, string searchText){
ISearchIndexClient infoClient = CreateSearchIndexClient();
string indexname = infoClient.IndexName;
DocumentSearchResult<Document> results = infoClient.Documents.Search(searchText);
await turnContext.SendActivityAsync(MessageFactory.Text($"Here should be the results: {results} \n...and then my index: {indexname}."));
}
It runs without errors, so one could use it. But it never shows the message at StartAsync. If anyone sees what I am missing, thank u in advance.
Related
I'm using C# in Visual Studios to create a Blazor App to connect to an Azure Database. Bit new to Blazor/Azure but I managed to get it working and retrieve the data.
I was initially using IServiceCollection.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie()
This all works fine, I'm looking to use Azure's Active Directory to verify users, which seems to work on its own, but now when the code does:
await Container.ReadItemAsync
it doesn't return the ItemResponse (or anything at all).
I've tried Googling the issue, but I haven't found anything relevant. I assume that there is an issue connecting to the azure DB relating to permissions, but I can't work out how to change it. Being new to cloud development, I'm not versed in the lingo. :)
Thanks,
Please try this:
Instead of string use JObject to return value.
instead of:
ItemResponse<string> result = await container.ReadItemAsync<string>(documentDBStorageId, PartitionKey.None, iro);
use this code:
ItemResponse<JObject> result = await container.ReadItemAsync<JObject>(documentDBStorageId, PartitionKey.None, iro);
return result.Resource.ToString();
I would like connect to existing Azure Storage Table and read (filtered) data from it.
I found some examples, but everyone used deprecated WindowsAzure.Storage namespace. I can not found any solution for Azure.Storage.Common or some else from current Microsoft namespaces. There is many examples for Azure.Storage.Blobs, but i need solution for Table Storage service. Thanks much ...
The Azure.Data.Tables package is the current generation update to the Tables client library and is currently in beta. Samples can be found in the Azure SDK repository in the Tables sample area.
Another suggested solution is to use the Microsoft.Azure.Cosmos.Table package. As stated in the description:
When used with Azure Table Storage service, this library offers similar APIs and functionalities as WindowsAzure.Storage 8.7.0.
Its full documentation can be found here.
A code sample that helps you get a connection to a table and do actions in the below:
private async Task<CloudTable> GetTable() {
var storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
var tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());
var table = tableClient.GetTableReference(TableName);
await table.CreateIfNotExistsAsync();
return table;
}
I am currently working on a project where we have data stored on Azure Datalake. The Datalake is hooked to Azure Databricks.
The requirement asks that the Azure Databricks is to be connected to a C# application to be able to run queries and get the result all from the C# application. The way we are currently tackling the problem is that we have created a workspace on Databricks with a number of queries that need to be executed. We created a job that is linked to the mentioned workspace. From the C# application we are calling a number of API's listed here in this documentation to call an instance of the job and wait for it to be executed. However I have not been able to extract the result from any of the APIs listed in the documentation.
My question is this, are we taking the correct approach or is there something we are not seeing? If this is the way to go, what has been your experience in extracting the result from a successfully run job on Azure Databricks from a C# application.
Microsoft has a nice architecture reference solution that might help you get some more insights too.
I'm not sure using the REST API is the best way to go to get your job output from Azure DataBricks.
First of all the REST API has a rate limit per databrick instance. It's not that bad at 30 requests per second but it strongly depend on the scale of your application and other uses of the databrick instance if that is sufficient. It should be enough for creating a job but if you want to poll the job status for completion it might not be enough.
There is also a limited capacity in datatransfer via the REST API.
For example: As per the docs the output api will only returns the first 5MB of a run output. If you want larger results you'll have to store it somewhere else before getting it from your C# application.
Alternative retrieval method
In Short: Use Azure PaaS to your advantage with blobstorage and eventgrid.
This is in no way an exhaustive solution and I'm sure someone can come up with a better one, however this has worked for me in similar usecases.
What you can do is write the result from your job runs to some form of cloud storage connected to databricks and then get the result from that storage location later. There is a step in this tutorial that shows the basic concept for storing the results of a job with SQL data warehouse, but you can use any storage you like, for example Blob storage
Let's say you store the result in blobstorage. Each time a new job output is written to a blob, you can raise an event. You can subscribe to these events via Azure Eventgrid and consume them in your application. There is a .net SDK that will let you to do this. The event will contain a blob uri that you can use to get the data into your application.
Form the docs a blobcreated event will look something like this:
[{
"topic": "/subscriptions/{subscription-id}/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/my-storage-account",
"subject": "/blobServices/default/containers/test-container/blobs/new-file.txt",
"eventType": "Microsoft.Storage.BlobCreated",
"eventTime": "2017-06-26T18:41:00.9584103Z",
"id": "831e1650-001e-001b-66ab-eeb76e069631",
"data": {
"api": "PutBlockList",
"clientRequestId": "6d79dbfb-0e37-4fc4-981f-442c9ca65760",
"requestId": "831e1650-001e-001b-66ab-eeb76e000000",
"eTag": "\"0x8D4BCC2E4835CD0\"",
"contentType": "text/plain",
"contentLength": 524288,
"blobType": "BlockBlob",
"url": "https://my-storage-account.blob.core.windows.net/testcontainer/new-file.txt",
"sequencer": "00000000000004420000000000028963",
"storageDiagnostics": {
"batchId": "b68529f3-68cd-4744-baa4-3c0498ec19f0"
}
},
"dataVersion": "",
"metadataVersion": "1"
}]
It will be important to name your blobs with the required information such as job Id and Run Id. You can also create custom events, which will increase the complexity of the solution but will allow you to add more details to your event.
Once you have the blob created event data in your app you can use the storage SDK to get the blobdata for use in your application. Depending on your application logic, you'll also have to manage the job ID and run Id's in the application otherwise you run the risk of having job output in your storage that is no longer attached to a process in your app.
Your use case is to use databricks as a compute engine (something similar to MySQL) and get output into C# application . So the best way is to create tables in databricks and run those queries via ODBC connection .
https://learn.microsoft.com/en-us/azure/databricks/integrations/bi/jdbc-odbc-bi
This way you have more control over sql query output.
I have an azure function that uses the Azure context. When I execute my function from visual studio 2019 on my machine, it executes correctly. However when I publish this to my Azure account, I get an error that the my.azureauth file cannot be found.
Could not find file 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12950\32bit\my.azureauth'
The code that is used:
var authFilePath = "my.azureauth";
Console.WriteLine($"Authenticating with Azure using credentials in file at {authFilePath}");
azure = Azure.Authenticate(authFilePath).WithDefaultSubscription();
sub = azure.GetCurrentSubscription();
Console.WriteLine($"Authenticated with subscription '{sub.DisplayName}' (ID: {sub.SubscriptionId})");
This is code that I found on one of the Microsoft tutorials. I have set my my.azureauth file to "Copy Always".
Could anyone point my in the right direction?
You are get this file path because the Directory.GetCurrentDirectory() would return D:\Program Files (x86)\SiteExtensions\Functions\2.0.12950\32bit instead of D:\home\site\wwwroot\ or D:\home\site\wwwroot\FunctionName.
And if you want to get the wwwroot folder or the function app directory you should use ExecutionContext. Further more information you could refer to this wiki doc.
So the right file path should be context.FunctionDirectory+"\my.azureauth" or context.FunctionAppDirectory+"\my.azureauth", which one to use depends on where your file is stored.
I have found that Kudu is extremely useful in seeing what has been deployed to Azure.
Navigate to your function in the Azure portal.
The instructions here will help get to the kudu console.
https://www.gslab.com/blogs/kudu-azure-web-app
From there you can browse the files which have been deployed into your function's file system.
If you add " , ExecutionContext context)" at the end of the function's run entry point, you can then get the folder which your function is running from with "var path = context.FunctionAppDirectory;
PS apologies for any formatting I am editing this on my phone.
Welcome to Stackoverflow.
Firstly, I'd recommend strongly against using file-based authentication as shown in your question.
From notes:
Note, file-based authentication is an experimental feature that may or may not be available in later releases. The file format it relies on is subject to change as well.
Instead, I would personally store the connection string details (AzureCredentials) in the config file (Web/SiteSettings) and use the provided constructor...
Again, the below are taken from the documentation notes:
Similarly to the file-based approach, this method requires a service principal registration, but instead of storing the credentials in a local file, the required inputs can be supplied directly via an instance of the AzureCredentials class:
var creds = new AzureCredentialsFactory().FromServicePrincipal(client, key, tenant, AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Authenticate(creds).WithSubscription(subscriptionId);
or
var creds = new AzureCredentialsFactory().FromServicePrincipal(client, pfxCertificatePath, password, tenant, AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Authenticate(creds).WithSubscription(subscriptionId);
where client, tenant, subscriptionId, and key or pfxCertificatePath and password are strings with the required pieces of information about your service principal and subscription. The last parameter, AzureEnvironment.AzureGlobalCloud represents the Azure worldwide public cloud. You can use a different value out of the currently supported alternatives in the AzureEnvironment enum.
The first example is most likely the one you should be looking at.
The notes I got this information from can be accessed here.
If you have some problems with AAD, these screenshots may help you.
Client ID:
Key:
Please note that the Key value can only be copied when it is created, after which it will be hidden.
Hope this helps you get started with AAD quickly.
so I'm looking to code in some music functionality to a bot that I'm making. I've tried a whole bunch of different search terms but can't seem to come up with anything.
I'm writing the bot in C# .NET Core
I've got the basics down. Connects to a voice channel etc. But I'm not sure how to interface it with YouTube/Spotify so that it could search for url's or song titles.
So for example I'd like to be able to give it a link like this (either youtube or spotify):
Or be able to search Youtube (or both) for a song title:
I'm sure there's some kind of library to download or a NuGet package or API that I can integrate, but I just can't seem to find the right search terms to use to find any tutorials or documentation on the topic.
Any help in this area would be appreciated
Well I have been in your shoes and the best solution is to abandon all native ffmpeg and all and just use Sharplink. It uses lavalink to send audio to discord without actually connecting to it.
DiscordSocketClient client = new DiscordSocketClient();
LavalinkManager lavalinkManager = new LavalinkManager(client, new LavalinkManagerConfig
{
RESTHost = "localhost",
RESTPort = 2333,
WebSocketHost = "localhost",
WebSocketPort = 2333,
Authorization = "YOUR_SECRET_AUTHORIZATION_KEY",
TotalShards = 1
});
This is how you would get started.
Once a LavalinkManager is set up it will need to be started. It is recommended you put this in the ready event.
client.Ready += async () =>
{
await lavalinkManager.StartAsync();
}
Real the docs at https://github.com/Devoxin/SharpLink
Good Luck
**EDIT: **
I made my music bot public so https://github.com/rishav394/Dota-Geek/ here it is. Look out for the music section.