Chatter Bot for Feeds enables you to post Chatter messages authored by any user. The best part is that you can automate these messages with Process Builder or Flow! Although there are many ways to post Chatter messages in Salesforce using Process Builder, Flow, Apex, or API, no one approach satisfied all of my requirements:
- Must be easy to use and launchable by Process Builder or Flow (declarative)
- Must support setting the author to someone other than the running user
- Must support rich-text
- Must support @ mentions
To learn more about my design decisions, please read my blog post introducing Chatter Bot for Feeds.
- Follow the Getting Started steps and deploy Chatter Bot for Groups. (the examples depend on this)
- Deploy Chatter Bot for Feeds.
- In Setup, create an Email Service using apex class
ChatterBotPostMessageEmailHandler
then create an Email Address. Set the Context User for the email service address to an administrator user. Take note of the generated email address as we will use it in a future step. - Assign the Chatter Bot Feeds Admin permission set to the Context User you chose. This allows setting the author for new Chatter posts to someone other than the current user.
- Create a Chatter Free user and set their email address to be the same as the Email Service Address from Step 3.
- Create a default organization default value for the Chatter Bot Feeds Setting custom setting and copy into the Email Service Address User ID field the ID of the Chatter Free user from Step 5.
- To test, add yourself or another user to a Chatter Group monitored by Chatter Bot for Groups (see Step 1). Within a couple seconds you should be able to refresh that group's feed and see the welcome post. Congratulations!
Now that you have all the configuration in place, now it's time to focus on your actual use cases for automating Chatter posts and deciding who you want the author to be in each of those scenarios.
Refer to the Chatter Bot Post Message Template email template for examples of supported rich-text in Chatter posts and the syntax for @ mentions. Your messages can also include merge fields from a record identified by the variable Record ID (Template Merge Fields) when invoking the CB: Post Message Apex method in Process Builder.
Alternatively, rather than specify values for Email Template Unique Name
and Record ID( Template Merge Fields
variables, you can use the Message
variable to specify your Chatter message right within Process Builder. Sometimes that is an easy option for simple messages.
Refer to the example process named Chatter Bot - Welcome New Group Member. There is one Immediate Action that demonstrates how to invoke the CB: Post Message Apex method. By default, the Author User ID is set the $User.Id
, the current user who causes the process to fire. For your purposes, you will want to change that to your desired Chatter post author such as a community manager, the CEO, a comical Chatter Free user, whatever.
As the #AwesomeAdmin that you are, you understand that with great power comes great responsibility. Impersonate other users on Chatter with care and always have consent from the intended author before automating posts by them. Thanks!
Why do I get error "The object named Chatter_Bot_Group_Member__c can't be found." during deployment?
The example Process Builder included in Chatter Bot for Feeds is designed for the use case when users join a group. That capability is only provided through Chatter Bot for Groups. See also question Can Chatter Bot for Feeds be used without Chatter Bot for Groups?.
In practice, yes. For deployment, not at this time. The example Process Builder included in Chatter Bot for Feeds is designed for the use case when users join a group. That capability is only provided through Chatter Bot for Groups. Once deployed, you can begin automating Chatter posts for any reason you want using Process Builder or Flow. The dependency on Chatter Bot for Groups is just for the example Process Builder.
The Email Service is only so that we can get code to execute as an administrator and not the current user. Technically, you don't need it to post Chatter messages unless you have these three requirements:
- You want to set the author to someone other than the running user
- You want to post a rich-text message
- You want to @ mention users or groups
To learn more about my design decisions, please read my blog post introducing Chatter Bot for Feeds.
Not for any technical reason to get this solution to work but rather to avoid using up any of your org's daily email quota. Apex can send a certain number of emails to external addresses each day, but an unlimited number of emails can be sent to internal users. Using a Chatter Free user for this purpose is a free and easy way around the Apex limitation.
You can specify a User ID, Chatter Group ID, or record ID where you would like the Chatter post to be made. If you specify a FeedItem ID (a Chatter post ID) then a FeedComment will be created for that Chatter conversation instead of a whole new Chatter post.