Slack is a cloud-based communication tool. In this scenario, we will have Method:CRM post information to Slack in a specific channel in real-time by the click of a button.
This is useful in a number of situations, for example, you could have your Web To Lead form update a Slack channel when a potential client fills it in. In this scenario, we will simply post information about a chosen contact to a channel when a button is pressed.
In order for this to work, you will need to have the proper permissions in Slack to add apps.
1. Log into Slack on your browser.
2. Navigate to http://api.slack.com and select the green Start Building button.
3. You will go to a new page, and this Create a Slack App dialog box will automatically pop up to start creating your app. Fill in the App Name and the Slack Workspace you want to use. Then select Create App.
4. The next screen shows your Basic Information. Here, select Incoming Webhooks, either from the left menu or under Add features and functionality.
5. The next screen is Incoming Webhooks. Toggle it to On, and then select the button at the bottom, Add New Webhook to Workspace.
6. The next screen gives authorization for your app to post. Select the channel you will have Method:CRM post to, and then select the Authorize button. In the below example, we are going to post to the #method channel.
7. You now have a Webhook URL which we will need for later! Copy that!
Now that you have the Webhook URL, you are set to go into Method:CRM to use it!
Using Method:CRM's Call Web Service Action
The next part will use Method:CRM's Call Web Service Action to send information within Method:CRM to the Slack workspace configured above.
In our example, the Call to Web Service action will be triggered via a button I created called Send details to Slack. This button will use the information in the dropdown control which will contain a contact.
Please note that having a strong handle on customization is required. We will not go into the details of the actions being used. Also note that we will not go into Field validation.
1. Within the Click event of the button, create an Assign Value to Action Result.
2. For Assign the value, I will use the following JSON text below. This is the JSON we will be sending to SLACK. For more information on creating a message in JSON to send, please see Slack's article: Incoming Webhooks.
"title": "A Message from Method",
"text": "This is information on a contact:",
"footer": "Method System Bot",
"title": "Contact Name",
"title": "Contact Email",
3. For Give it a name, I called the action result resultSlackBody.
4. Next up, I'm going to use Merge fields. If you look at the above JSON, you will notice I want to send information from the contacts table. I'm going to replace all the instances of Contacts.fieldname with their respective values using the Character Functions action.
5. And now we can add the Call Web Service action!
Web Service Type: REST
Endpoint URL: Enter Webhook URL you created above when configuring Slack.
HTTP Method: POST
Content Type: JSON
Parameter Name: Content-Type
Value From: Text
Body - Value From: Action Result resultSlackBody
6. Close and save the screen.
And that's it! Your web service is set up!
When I press the button and check slack in my #method channel, this is what I see: