Example: Apex Class for Time Selector Messaging Components
Time selector messaging components send customers a prompt and a list of available time
slots for them to choose from. To generate the list of time slots each time the component is sent,
create an Apex class. The Apex class determines the time slot start time, duration, and time
zone.
Enhanced In-App Chat, Enhanced Web Chat v1, Enhanced WhatsApp, Enhanced Facebook
Messenger, and Enhanced Apple Messages for Business, and Bring Your Own
Channel
This article doesn’t apply to:
Enhanced Web Chat v2, Standard Facebook Messenger, Standard and Enhanced SMS, and
Enhanced LINE
This Apex class provides example time slots at several intervals, each set by a pair of
Datetime statements.
Example
public with sharing class MessagingTimeSlotOptions {
@InvocableMethod
public static List<List<RichMessaging.TimeSlotOption>> getTimeSlotOptions(){
List<List<RichMessaging.TimeSlotOption>> result = new List<List<RichMessaging.TimeSlotOption>>();
List<RichMessaging.TimeSlotOption> options = new List<RichMessaging.TimeSlotOption>{
new RichMessaging.TimeSlotOption(
Datetime.now().addHours(1),
Datetime.now().addHours(2)),
new RichMessaging.TimeSlotOption(
Datetime.now().addHours(3),
Datetime.now().addHours(4)),
new RichMessaging.TimeSlotOption(
Datetime.now().addHours(25),
Datetime.now().addHours(26)),
new RichMessaging.TimeSlotOption(
Datetime.now().addHours(27),
Datetime.now().addHours(28))
};
result.add(options);
return result;
}
}
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required Cookies
Always Active
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional Cookies
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising Cookies
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.