Parser Registry Plug-in
The parser registry plug-in adds a custom interface that allows:
- email parsers to be added to Jancy that can be used to locate and parse different types of emails using either the
gmail
orimap
resolver. - sms parsers to be added to Jancy that can be used to parse text messages from various services captured by SMS providers (e.g.
seatheros
,textchest
) - adds a custom Jancy page at
jancy://parsers
that, if visited in Jancy, will display all the registed email parsers.
A handle to the parser registry can be retrieved via jancy.getInterface('parserRegistry')
.
Parser Registry Interface Methods
parserRegistry.registerParser(type, key, parser)
type
(string
) – can either be"email"
or"sms"
key
(string
)parser
(object
)
Registers a specialized parser object that customizes how either email profile resolvers will find emails and parse their contents or how sms profile resolvers will parse text messages.
The parser
object when type is email
needs to have the following functions defined on it.
canRun(jancy, args)
jancy
(Jancy object
)args
(Resolver object
)
canRun
should returntrue
if the parser can run based onargs
orfalse
otherwise
canRun(jancy, args) { return (args.resolverName === 'gmail' || args.resolverName === 'imap') && args.profile?.email && args.site === 'ticketmaster' }
getQuery(jancy, args)
jancy
(Jancy object
)args
(Resolver object
)
getQuery
should eihter return a query string using Gmail search operators if the current resolver isgmail
or an ImapFlow SearchObject if the current resolver isimap
.
getQuery(jancy, args) { if (args.resolverName === 'gmail') { return `{subject:"Here's Your Authentication Code" subject:"Your request to reset password"} to:${ args.profile.email }` } // args.resolverName === 'imap' return { to: args.profile.email, or: [ { subject: "Here's Your Authentication Code" }, { subject: "Your request to reset password" } ] } }
parseMessage(jancy, args, msg)
jancy
(Jancy object
)args
(Resolver object
)msg
(Message object
)
parseMessage
will get a the first email found by the query returned bygetQuery
.parseMessage
should attempt to parse the contents of the given message and return astring
that will be used as the resolved value for the profile resolver.
The parser
object when type is sms
needs to have the following functions defined on it.
parseMessage(jancy, args, msg)
jancy
(Jancy object
)args
(Resolver object
)msg
[string
]
parseMessage
should attempt to parse the contents of the given message and return a string
that will be used as the resolved value for the profile resolver.
emailParserRegistry.unregisterParser(key)
type
(string
) – can either be"email"
or"sms"
key
(string
)
Unregisters a previously registered parser.