Last active
May 13, 2019 09:52
-
-
Save rike422/e45581f58a6bc5796a5ca7699e579606 to your computer and use it in GitHub Desktop.
メール処理用のRuby製botフレームワークを作った(作っている) ref: https://qiita.com/rike422/items/46f02d073faf3b8e5176
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'slack-ruby-client' | |
module Rounders | |
module Handlers | |
class Invoice < Rounders::Handlers::Handler | |
# メールをフィルタリングするAND条件、第二引数に渡したSymbolはメソッド名 | |
on({ | |
subject: 'Amazon Web Services Invoice Available', | |
from: '[email protected]' | |
}, :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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ※適当なコード | |
Mail.all.each do |mail| | |
if mail.subject == "期待する件名" | |
# なにがしかの処理 | |
end | |
if mail.body == "期待するbody" | |
# なにがしかの処理 | |
end | |
#延々と続く条件式・・・ | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rounders | |
module Stores | |
class Conne < Rounders::Stores::Store | |
config :file, required: true, type: String | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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