A simple cross-platform library for building VUI smart speaker skills using C#.
- Google Assistant
- Amazon Alexa
- LINE Clova
Create a class that inherits AssistantBase
.
public class MyAssistant : AssistantBase
{
}
*If you need more properties or methods, use an extended interface.
public interface ILoggableAssistant : IAssistant
{
ILogger Logger { get; set; }
}
public class MyAssistant : AssistantBase, ILoggableAssistant
{
public ILogger Logger { get; set; }
}
Instantiate the derived class.
var Assistant = new MyAssistant();
If you want to use Dependency Injection, call AddAssistant
extension method in the Startup class.
public void ConfigureServices(IServiceCollection services)
{
services.AddAssistant<IAssistant, MyAssistant>();
services.AddMvc();
}
Pass request object to handle request and create response.
var response = await Assistant.RespondAsync(req, Platform.GoogleAssistant); // specify platform
return new OkObjectResult(response.ToGoogleAssistantResponse());
Override methods executed for each request type or event.
public class MyAssistant : AssistantBase
{
protected override Task OnLaunchRequestAsync(
Dictionary<string, object> session, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
protected override Task OnIntentRequestAsync(
string intent, Dictionary<string, object> slots, Dictionary<string, object> session,
CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
You can add content for response of Assistant Extension to Response
property with method chaining.
1. Add Reply.
Response
.Speak("お元気ですか?") // Speek simple text
.Break(3) // Pause for 3 seconds.
.Play("https://dummy.domain/myaudio.mp3"); // Play mp3 audio.
2. Keep listening for multi-turn session and add reprompt.
Response
.Speak("お元気ですか?")
.KeepListening("元気かどうか教えてください。");
3. Play audio with AudioPlayer / Media responses.
Response.PlayWithAudioPlayer(
"sample-id", // audio item id
"https://dummy.domain/myaudio.mp3", // audio url
"Sample Title", "Sample Subtitle").
4. Different responce for each platform
Response
.Speak("私はグーグルです。", Platform.GoogleAssistant)
.Speak("私はアレクサです。", Platform.Alexa)
.Speak("私はクローバです。", Platform.Clova);
5. Different processing for each platform
if (Request.CurrentPlatform == Platform.Clova)
{
// Push LINE Message to same account
await lineMessagingClient.PushMessageAsync(Request.UserId, "Hello!");
}