Skip to content

Instantly share code, notes, and snippets.

@sanjay-btc
Created April 10, 2019 11:51
Show Gist options
  • Save sanjay-btc/71fe5fc0c7ec71c3ca9818479a8965ba to your computer and use it in GitHub Desktop.
Save sanjay-btc/71fe5fc0c7ec71c3ca9818479a8965ba to your computer and use it in GitHub Desktop.
class ApplicationMailbox < ActionMailbox::Base
routing ->(inbound_email) { with_sku?(inbound_email) } => :price_finder
def self.with_sku?(inbound_email)
inbound_email.mail.subject.include?('SKU') || inbound_email.mail.body.include?('SKU')
end
end
class PriceFinderMailbox < ApplicationMailbox
def process
# Extract product_id and quantities
# Call API to get the price of the product
# total price = quantities * price
# Draft email and send this price to sender via email.
Quotation.with_price(mail.to.first).deliver_now
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment