C# SDK for Clova Extension Kit. Available on NuGet: https://www.nuget.org/packages/CEK.CSharp/
Create a class that inherits ClovaBase
.
public class MyClova : ClovaBase
{
}
*If you need more properties or methods, use an extended interface.
public interface ILoggableClova : IClova
{
ILogger Logger { get; set; }
}
public class MyClova : ClovaBase, ILoggableClova
{
public ILogger Logger { get; set; }
}
Instantiate the derived class.
var clova = new MyClova();
If you want to use Dependency Injection, call AddClova
extension method in the Startup class.
public void ConfigureServices(IServiceCollection services)
{
services.AddClova<IClova, MyClova>();
services.AddMvc();
}
Default language is Lang.Ja
, but you can change it.
clova.SetDefaultLang(Lang.En);
or pass in ClovaConfiguration
:
var config = new ClovaConfiguration { DefaultLang = Lang.En };
builder.Services
.AddSingleton(config)
.AddClova<IClova, MyClova>();
public class MyClova : ClovaBase
{
public MyClova(ClovaConfiguration config)
{
SetDefaultLang(config.DefaultLang);
}
}
Pass Signature Header and Body to handle request and create response.
var response = await clova.RespondAsync(Request.Headers["SignatureCEK"], Request.Body);
return new OkObjectResult(response);
*If you want to skip validation, pass true at the end.
var response = await clova.RespondAsync(Request.Headers["SignatureCEK"], Request.Body, true);
Override methods executed for each request type or event.
public class MyClova : ClovaBase
{
protected override async Task OnLaunchRequestAsync(
Session session, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
*Available virtual methods
Method | Parameters |
---|---|
OnLaunchRequestAsync | Session session, CancellationToken cancellationToken |
OnIntentRequestAsync | Intent intent, Session session, CancellationToken cancellationToken |
OnEventRequestAsync | Event ev, Session session, CancellationToken cancellationToken |
OnSkillEnabledEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnSkillDisabledEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnPlayFinishedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnPlayPausedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnPlayResumedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnPlayStartedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnPlayStoppedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnProgressReportDelayPassedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnProgressReportIntervalPassedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnProgressReportPositionPassedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnStreamRequestedEventAsync | Event ev, Session session, CancellationToken cancellationToken |
OnSessionEndedRequestAsync | Session session, CancellationToken cancellationToken |
OnUnrecognizedRequestAsync | CEKRequest request, CancellationToken cancellationToken |
You can add content for response of Clova Extension to Response
property with method chaining.
When you add the text, you can also set the language to overwrite default language.
1. Add Reply.
Response
.AddText("こんにちは!")
.AddUrl("https://dummy.domain/myaudio.mp3")
.AddText("Hi!", Lang.En)
.AddUrl("https://dummy.domain/myaudio.mp3", Lang.En);
2. Add Brief/Verbose.
Response
.AddBriefText("Brief explain.", Lang.En)
.AddVerboseText("Detail explain 1.", Lang.En)
.AddVerboseText("Detail explain 2.", Lang.En)
.AddVerboseUrl("https://dummy.domain/myaudio.mp3");
3. Add Reprompt.
Response
.AddRepromptText("Tell me something, please", Lang.En)
.AddRepromptUrl("https://dummy.domain/myaudio.mp3");
4. Add session value.
Response.SetSession("mySessionKey", "mySessionValue");
5. Keep listening for multi-turn session.
Response
.AddText("What do you want?", Lang.En)
.KeepListening();
You can use CEK's AudoPlayer through the simple methods.
Method | Parameters |
---|---|
PlayAudio | Source source, AudioItem audioItem, AudioPlayBehavior playBehavior |
EnqueueAudio | Source source, params AudioItem[] audioItems |
PauseAudio | - |
ResumeAudio | - |
StopAudio | - |