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
gmailorimapresolver. - 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://parsersthat, 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)
canRunshould returntrueif the parser can run based onargsorfalseotherwise
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)
getQueryshould eihter return a query string using Gmail search operators if the current resolver isgmailor 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)
parseMessagewill get a the first email found by the query returned bygetQuery.parseMessageshould attempt to parse the contents of the given message and return astringthat 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.