Hi There! I’m working on a rather complicated project and need some advice/help getting it off the ground.
I’m using Laravel 5.2 as my framework.
I have 5 inboxes that I have my application monitoring.
The goal is to detect ‘new’ emails (that are not replies, etc) and process them according to which inbox the email hit. (I will detect emails that DON’T need processing based on the “from” and “subject” of the emails.)
The issue is, each of these 5 types are handled slightly differently. And beyond that, each inbox expects emails of various formats/templates.
My 5 inboxes:
orders
serviceInvoices
sampleRequests
shipmentNotices
inbounds
For example:
orders…
an order will come from an expected sender (so I can determine the format it should be in).
- ABC company has the PO# and buyer in the body of the email with a link to download the invoices. So, I would like my system to be able to login to that site and download the order. (Usually there is more than 1 order in an email from this company)
- XYZ company sends us a PDF of the order attached to the email and the PO # is in the filename (and sometime subject too)
- DEF company has a person send us the orders (as a pdf, with the filename containing the PO#)
So, processing ABC’s order, I would
- save the email to DB
- scrape the email for the invoice numbers.
- based on the # of matches, create new ‘orders’ in the DB
- visit the portal and download the attachments and associate them with a foreign_key to the ‘orders’ created above.
- fire an event that a new PO was imported
- send notifications to subscribers of this event for the client in question
For provider invoices, it’s somewhat similar. Except, sometimes there will be 1-4 invoices per email.
These need to be saved, scraped, assigned to a serviceProvider, then the document scraped and attempt to assign a client to the invoice and charges associated.
For the shipment notices, sometimes we get the shipment notice as one file for multiple shipments. I need to divide the PDF into the proper number of pages for each shipment, then find the PO that the shipment notice is associated to, save it to the db, fire an event, and send the document to the appropriate parties.
and so on and so on…
Methods I’ve Considered/Tried:
[ul][li]make an DTO event for each inbox and fire the event when an email is received.[/li]
[list]
[li]the listener, then uses Chain of Responsability to send it through various handlers (SaveEmailToDB.php, AddToLogFile.php, CreateProviderInvoice.php, SaveAttachments.php)[/li]
[li]this didn’t feel right and I’m getting lost with these Classes, because some of these actions, I want to be able to reuse elsewhere. (I want there to be a front end portal where invoices, orders, etc can be entered manually as well)[/li]
[/list]
[li]make a DTO event for each inbox and fire the event[/li]
[list]
[li]the listener then checks the from and subject and gets a scraper that implements an interface for scraping that inbox type (ie, abstract ProviderInvoiceScraper) ClientABCInvoiceScraper implements ProviderInvoiceScraper). Then, the Listener doesn’t need to care about the content or type and I could make individual scrapers for each type of email.[/li]
[li]This didn’t feel quite right either… I’m not sure of the best way to implement this… =[/li]
[/list][/ul]
I would love any suggestions on how to approach this and what I can try differently to accomplish this.
Thank you!