Builder for
Message objects.
Example usage:
// Create a message builder.
var messageBuilder = AdsApp.extensions().newMessageBuilder();
// Create a message operation.
var messageOperation = messageBuilder
.withBusinessName("business") // required
.withCountryCode("US") // required
.withPhoneNumber("1234567891") // required
.withExtensionText("extension") // required
.withMessageText("message text") // required
.build();
// Optional: examine the outcome. The call to isSuccessful()
// will block until the operation completes.
if (messageOperation.isSuccessful()) {
// Get the result.
var message = messageOperation.getResult();
} else {
// Handle the errors.
var errors = messageOperation.getErrors();
}
Methods:
build()
Creates a
Message. Returns a
MessageOperation that can be used to get the new
message (or access any associated errors if creation failed).
Return values:
withBusinessName(businessName)
Sets the advertiser's business name. This field is required.
Arguments:
Name | Type | Description |
businessName |
String |
The business name of the advertiser. |
Return values:
withCountryCode(countryCode)
Sets the two character country code of the advertiser's phone number. This field is required.
Arguments:
Name | Type | Description |
countryCode |
String |
The country code for the phone number. |
Return values:
withEndDate(date)
Sets the message's end date from either an object containing year, month, and
day fields, or an 8-digit string in
YYYYMMDD
format. This field is optional.
For instance, messageBuilder.withEndDate("20130503");
is equivalent
to messageBuilder.withEndDate({year: 2013, month: 5, day: 3});
.
The change will fail and report an error if:
- the given date is invalid (e.g.,
{year: 2013, month: 5, day: 55}
),
- the start date now comes after the end date, or
- it's a date in the past
Arguments:
Name | Type | Description |
date |
Object |
The new message end date. |
Return values:
withExtensionText(extensionText)
Sets the extension text shown in the ad. This field is required.
Arguments:
Name | Type | Description |
extensionText |
String |
The extension text shown in the ad. |
Return values:
withMessageText(messageText)
Sets the message text populating the messaging app. This field is required.
Arguments:
Name | Type | Description |
messageText |
String |
The message text populating the messaging app. |
Return values:
withMobilePreferred(isMobilePreferred)
Sets the message's device preference to mobile or clears it. This field is
optional and defaults to
false
.
Arguments:
Name | Type | Description |
isMobilePreferred |
boolean |
Whether or not this message should be mobile
preferred. If true is passed in, device preference will be set to mobile. If false is passed in, device preference will be set to none. |
Return values:
withPhoneNumber(phoneNumber)
Sets the advertiser's phone number that gets appended to the ad. This field is required.
Arguments:
Name | Type | Description |
phoneNumber |
String |
The phone number as a string. |
Return values:
withSchedules(schedules)
Sets the message scheduling. Scheduling of a message allows
you to control the days of week and times of day during which the message will
show alongside your ads.
Passing in an empty array clears the scheduling field, causing the message
to run at all times.
The following example sets the message to run on Mondays and Tuesday from
8:00 to 11:00.
var mondayMorning = {
dayOfWeek: "MONDAY",
startHour: 8,
startMinute: 0,
endHour: 11,
endMinute: 0
};
var tuesdayMorning = {
dayOfWeek: "TUESDAY",
startHour: 8,
startMinute: 0,
endHour: 11,
endMinute: 0
};
messageBuilder.withSchedules([mondayMorning, tuesdayMorning]);
Arguments:
Return values:
withStartDate(date)
Sets the message's start date from either an object containing year, month,
and day fields, or an 8-digit string in
YYYYMMDD
format. This field is optional.
For instance, messageBuilder.withStartDate("20130503");
is
equivalent to messageBuilder.withStartDate({year: 2013, month: 5, day:
3});
.
The change will fail and report an error if:
- the given date is invalid (e.g.,
{year: 2013, month: 5, day: 55}
),
- the given date is after the message's end date,
Arguments:
Name | Type | Description |
date |
Object |
The new message start date. |
Return values: