Adding a Formatter

Old forums and posts related to unsupported version of Syn Virtual Assistant.

Adding a Formatter

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

Formatters came into existence in Syn Engine 2.0. Formatter helps make the last second textual replacement before a message is received by the Engine or a Response is generated for a Caller.

A typical usage of a Formatter can be filtering out words to standard words used by the internal SynData classes or an external bot that interacts with the Engine.

Example: They're | They are

Sample code to write a simple Formatter

CSharp Code

public sealed class FilterFormatter : SynFormatter
{
public override string Format(string message)
{
string toReturn = message;
toReturn = toReturn.Replace("they're", "they are");
toReturn = toReturn.Replace("we've", "we have");
toReturn = toReturn.Replace("its", "it is");
toReturn = toReturn.Replace("we'll", "we will");
return toReturn;
}
}


Sample code to add the above Formatter to the Engine

CSharp Code

FilterFormatter formatter = new FilterFormatter();
formatter.Mode = SynFormatter.FormatMode.Message;
Engine.AddFormatter(formatter);


In the above code the Mode determines as to where the Formatting would take place.
There are 3 types of Modes

  • Message
  • Response
  • Both

We chose Message hence if a message is received it will be formatted by the Formatter we created before its evaluated by the Engine
User avatar
Leslie
Lead Software Architect
 
Posts: 287
Joined: Fri Sep 14, 2012 12:20 pm

Return to Archived (Old Posts)

Who is online

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