Search code examples
asp.net-core-webapiactions-on-googlegoogle-smart-home

Is there a .NET client library for Google Smart Home Action?


I am building an endpoint to fulfill Google Smart Home Actions requests. I need to build this in ASP.NET Core. Is there a library I can use to wrap Google Smart Home Actions request? I am only seeing libraries for Node.js and Java.

Google Smart Home Actions libraries


Solution

  • There is not currently a fulfillment library for intent handling with .NET (although we are exploring the idea). However, you can use the Google APIs for .NET client library to communicate with the Home Graph service (used for features such as Request Sync and Report State).

    Here is a quick example of what the Home Graph client would look like in C#:

    try
    {
        // Create authorized client
        GoogleCredential credential = GoogleCredential.FromFile("service-account.json")
            .CreateScoped(new[] { "https://www.googleapis.com/auth/homegraph" });
        var service = new HomeGraphServiceService(
            new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "HomeGraphTester",
            });
    
        // Make Home Graph requests
        var request = new RequestSyncDevicesRequest{
          AgentUserId = "1234"
        };
        var response = service.Devices.RequestSync(request);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }