Spread the love

For those of you who has no idea of what the Ohana Community Italia is, please refer to this post I wrote in the late December 2017.

Long story short, we are building our own nation wide Salesforce community…

This is a handy GitHub repository with all the code needed to follow this article.

I want to document the build of this community, in terms of all the actions we’ll take to create all the little pieces.

Hopefully, we’ll create a public repository with all the code and stuff, so anyone could create what we are doing!

The Community

The idea is to build a Salesforce Community inside a dedicated ORG in order to easy communication and sharing of ideas between italian trailblazers.

Thanks to Nino Guarnacci, our amazing sponsor from Salesforce Italy, we have a dedicated Salesforce DE ORG with all the necessary licenses.

This requires to:

  • choose the best Salesforce Community for our needs
  • configure all the features of the community
  • create a registration page
  • cover of the base topics for the start up

This is not a simple task, I don’t mean technically, but in terms of time.

That’s why we decided at first to freeze the building of the community in a Salesforce ORG (that is actually been built on the background) and speed up the process of putting together people using a more common and well known tool, configuring a Slack workspace.

At the time of writing the Ohana Community Italia is live at italia.ohana.community and its topics are publicly available, although it’s been constantly improved day by day (let’s say we are on Beta).

ohana-community-italy.slack.com

Slack is a great tool for collaboration and it seemed a cool way to start.

That’s why we created the Ohana Community Italy Slack workspace.

The configuration of the workspace is quite simple, we have administrators and users, with different powers (it depends on how much power you want to give to your users):

But how do you get on the Slack community?

We decided to leave the invitation private at first.

Invitation happens in 2 ways:

  • Direct invitation by an admin
  • Form compilation of an invitation request

Web-To-Case invitation form

The idea is to create a new Case when a new trailblazer wants to join, using the web-to-lead feature (a pretty standard feature), that automatically generates a Case from a web form, exposed pubblicly on a Force.com site.

We took the auto-generated HTML form from the Salesforce setup and customized it based on our needs:

There is no need to enter in the details of this configuration, as there is plenty of stuff out there (Salesforce docs enter in enough details to get started).

Refer to the Subscribe.page on the repository.

Send invitation to Slack

And now?

Someone must send an email to invite the person who succesfully created a new Case on the ORG.

For the first times of the life of the Slack community we are handling this by hand, but we should soon automate this in a Case trigger (TO DO).

To send invitation links to specific email addresses we need:

      A Slack app linked to your slack workspace
      A page in the Case layout with a button to make the call
      The right REST commands to trigger the invitation email

Create a Slack App

Jump to https://api.slack.com/apps:

Create a new app and link it to a workspace (in this example I’m using my own personal Slack instance):

Espand Add features and functionality section and hit Permissions. Scroll down and add the Admin scope:

Now that you have at least one scope, you can install the app on your workspace:

Last thing to do, is generate a quick and dirty legacy token with full super powers on https://api.slack.com/custom-integrations/legacy-tokens:

Copy this token for next configuration.

A button to invite them all

A new VF page will be put inside the Case using the layout editor.
Refer to the OhanaCommunityInvitation.page on the repository.

This page simply takes a case (of a certain Record Type, Community_Management), and by pressing the Invite to Slack button makes a call to Slack to actually send the invitation email.

Take the SlackUtils class and update the oauthToken property placing the OAuth Slack legacy token generated in the previous section:

public class SlackUtils {
    /*
     * OAuth token for admin tasks took from https://api.slack.com/custom-integrations/legacy-tokens
     * TODO: replace with Custom Setting or Oauth Call
     */
    public static String oauthToken{
        get{
            return 'xoxp-XXXXXXX-XXXXXXXXXXXXX-XXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXX';
        }
    }

This class contains the main actions will be using for communicate with Slack.

You also need to enable the Slack API endpoint, you can easily do it using a Named Credential:

The invitation email is not a documented REST method, but I found a solution in Stack Overflow thread.

If the invitation is sent sucessfully, the case is automatically closed.
If the case is closed you still have a chance to re-send the email, using the resend=true parameter to the call.

Slack bot says: “Hey there’s a Case awaiting for an invitation!”

Invitation are not currently sent automatically, so we need a way to notify the administrators of the community so they can push the button (before you say a word…I know this is not the most comfortable flow).

We’ve built a scheduled Apex process that sends a notification every morning in a specific Slack channel: although this is not so comfortable, I admit I wanted to do this to write something with a bot from Salesforce to Slack!

The code is in the NotifyNewUsersOnSlackSch class and you should update the ohanaServiceChannel property to change the channel name.
In the SlackUtils class you can also change the Bot name and icon (the URL must be available pubblicly).

What’s next

Next steps are enable automatic Slack invitations on Case creation (the job is needed in case of errors or connection problems) and finally publish the Salesforce Community…but it is another story!

Remember to star the GitHub repository with all the code needed to follow this article.

Join the Ohana Community Italia, but you should at least say Hello in Italian!