Skip to content

Commit

Permalink
Add ntust email notify
Browse files Browse the repository at this point in the history
  • Loading branch information
jhang-jhe-wei committed Aug 27, 2021
1 parent 1f6ad62 commit 4e03bc9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/controllers/notifies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class NotifiesController < ApplicationController
http_basic_authenticate_with :name => ENV["HTTP_AUTH_USERNAME"], :password => ENV["HTTP_AUTH_PASSWORD"], only: [:version, :version_notify, :calendar, :calendar_notify]

skip_before_action :verify_authenticity_token, only: [:email_notify]
def index
@auth_link = LineNotify.get_auth_link(current_user.line_id)
end
Expand Down Expand Up @@ -39,6 +39,13 @@ def course_notify
render status: 200, json: {status: "OK"}
end

def email_notify
notify_type = "台科大大宗郵件"
message = "\n\n【台科大大宗郵件】\n#{params.dig(:output_data, :info_type)}\n#{params.dig(:output_data, :info_title)}\n#{params.dig(:output_data, :link_path)}"
SubscriptionDispatch.new(notify_type, message).perform
render status: 200, json: {status: "OK"}
end

def callback
code = params[:code]
current_user = User.find_by(line_id: params[:state])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def has_token?
end

def notify_present?
notifies = ["版本更新通知", "台科大行事曆", "上課提醒"]
notifies = ["版本更新通知", "台科大行事曆", "上課提醒", "台科大大宗郵件"]
render json: { type: "text", text: "沒有該通知,可能已被刪除或不存在!" } if notifies.exclude? params[:notify_type]
end

Expand Down
1 change: 1 addition & 0 deletions app/views/notifies/index.line.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
message_button "取消訂閱", "取消通知/上課提醒"
url_button "開始訂閱", liff_path(path: course_path), style: "primary", color: "#F3D23C"
end
page("台科大大宗郵件", "訂閱後學校的大宗郵件寄出時都會用 Line Notify 通知你哦!\n(改寫自 narihira2000 的 GAS-NTUST-bulletin)")
page("台科大行事曆", "訂閱後每天都會通知你近 7 日有關於台科大的活動哦!")
page("版本更新通知", "訂閱後有關於版本的更新都會通知你哦!")
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
post "notifies/calendar", to: "notifies#calendar_notify", as: "calendar_notify"
get "notifies/course", to: "notifies#course", as: "course"
post "notifies/course", to: "notifies#course_notify", as: "course_notify"
post "notifies/email", to: "notifies#email_notify"
#other
get "*other", to: "guides#other"
end

0 comments on commit 4e03bc9

Please sign in to comment.