Writing Your First Plugin

Developer tutorials for Prototype 8.0

Writing Your First Plugin

Postby Leslie » Thu Oct 02, 2014 6:25 pm

First of all you will need an IDE - I recommend you to have Visual Studio 2012 Express Edition - Click Here to Download

Now run Visual Studio and click File - > New Project - > ( Your Language C# / VB / C++ ) -> Class Library - > Name the Project MyPlugin

Now Add Reference to the Syn.Engine Library ( which is located in the Installation Directory of Syn Virtual Assistant )

Image

This tutorial is going to demonstrate how we can create a function called "Open Door" for a plugin that will interface with Syn Virtual Assistant.

Now Type in the Following:

CSharp Code

using Syn.Engine;
using Syn.Engine.Data;

namespace MyPlugin
{
public class MyPlugin : SynPlugin
{
public override void Initialize()
{
this.Engine.AddAutoParser(new OpenDoorCommand());
this.Engine.AddGear(new MyPluginGear());
}

public class OpenDoorCommand : SynData
{
public OpenDoorCommand()
{
this.Data.AddPattern("\b(open door)\b");
}
}

public class MyPluginGear : SynGear
{
public void OpenDoor(OpenDoorCommand command, IntegerData doorNumber)
{
command.Data.Caller.Respond("Door Number " + doorNumber.ToString() + " opened");
}
}
}
}


Visual Basic Code

Imports Syn.Engine
Imports Syn.Engine.Data

Public Class MyPlugin
Inherits SynPlugin

Public Overrides Sub Initialize()
Me.Engine.AddAutoParser(New OpenDoorCommand)
Me.Engine.AddGear(New MyPluginGear)
End Sub

Public Class OpenDoorCommand : Inherits SynData
Sub New()
Me.Data.AddPattern("b(open door)b")
End Sub
End Class

Public Class MyPluginGear : Inherits SynGear
Public Sub OpenDoor(command As OpenDoorCommand, doorNumber As IntegerData)
command.Data.Caller.Respond("Door Number " & doorNumber.ToString() & " opened")
End Sub
End Class

End Class


Now Click Build -> Build Automation. Then go to the Debug/Release Folder and copy the file Automation.dll

Image

And paste it in Syn Virtual Assistant's Plugin Folder

Image

Now type open door 7 in Syn Virtual Assistant's input box and it will respond Door number 7 has been opened
User avatar
Leslie
Lead Software Architect
 
Posts: 310
Joined: Fri Sep 14, 2012 12:20 pm

Return to Developer Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest
cron