How to create a slack notification for POWR One new users
We already have a lib called slack_wrapper.rb that has some methods there, the first one called notify_slack_channel and it's been used in a few places, and there is another one that was created recently called slack_notification.
From now on, try to use slack_notification if you need to create new slack notifications. In a soon future, we are going to refactor this lib and replace all places that are using notify_slack_channel by slack_notification.
So in onder to use this, you will need to include this lib in your file like this:
class Api::Platform::OnboardingController < Api::PlatformController
include SlackWrapper
and call it:
slack_notification(message, username, channel, attachments = [])
or, if you have any logic that you want to implement and keep you files clean, you can use this module API::Platform::Slack::Notifications and create a method there like this example:
def new_user_alert_slack(user, is_new_user = true)
channel = Rails.env.production? ? "#powr-one-new-users" : "#powr-one-test"
new_user_msg = "🎉🎉🎉 New User #{user.email} has joined POWR One! 🎉🎉🎉"
transfering_user_msg = "⚡️⚡️⚡️ EXISTING User #{user.email} has joined POWR One ⚡️⚡️⚡️"
message = is_new_user ? new_user_msg : transfering_user_msg
attachments = [
{
"color": "#36a64f",
"title": "User in TSH",
"title_link": "#{base_url}/admin/tech_support_helper?search_by_user=#{user.id}"
}
]
slack_notification(message, "POWR One", channel, attachments)
end
Note that in this file, we already included SlackWrapper there, so no need to include it again, just use slack_notification method.
Then, just include this module in your file:
class Api::Platform::OnboardingController < Api::PlatformController
include API::Platform::Slack::Notifications
and call it:
new_user_alert_slack(user, false)