User avatar
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Adding a Formatter

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;
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

Return to “Archived (Old Posts)”

Who is online

Users browsing this forum: No registered users and 2 guests