Skip to content

Instantly share code, notes, and snippets.

@rike422
Last active May 13, 2019 09:52
Show Gist options
  • Save rike422/e45581f58a6bc5796a5ca7699e579606 to your computer and use it in GitHub Desktop.
Save rike422/e45581f58a6bc5796a5ca7699e579606 to your computer and use it in GitHub Desktop.
メール処理用のRuby製botフレームワークを作った(作っている) ref: https://qiita.com/rike422/items/46f02d073faf3b8e5176
require 'slack-ruby-client'
module Rounders
module Handlers
class Invoice < Rounders::Handlers::Handler
# メールをフィルタリングするAND条件、第二引数に渡したSymbolはメソッド名
on({
subject: 'Amazon Web Services Invoice Available',
from: 'aws-receivables-support@email.amazon.com'
}, :aws)
def aws(mail, matches)
pdf = mail.attachments.first
slack_client.files_upload(
channels: '#hogehoge',
file: UploadIO.new(StringIO.new(pdf.decoded), 'application/pdf', pdf.filename),
title: mail.subject,
as_user: true,
filename: pdf.filename,
)
rescue => e
Rounders.logger.error e
end
def slack_client
@client ||= Slack::Web::Client.new
end
end
end
end
# ※適当なコード
Mail.all.each do |mail|
if mail.subject == "期待する件名"
# なにがしかの処理
end
if mail.body == "期待するbody"
# なにがしかの処理
end
#延々と続く条件式・・・
end
module Rounders
module Stores
class Conne < Rounders::Stores::Store
config :file, required: true, type: String
end
end
end
class Rounders::Application
 # 名前空間を小文字にして'.'で区切ったパスでアクセスできる
config.stores.yaml.file = '設定したいファイルパス'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment