AdWordsApp.​MessageBuilder

Builder for Message objects.

Example usage:

 // Create a message builder.
 var messageBuilder = AdWordsApp.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:

MemberTypeDescription
build AdWordsApp.MessageOperation Creates a Message.
withBusinessName AdWordsApp.MessageBuilder Sets the advertiser's business name.
withCountryCode AdWordsApp.MessageBuilder Sets the two character country code of the advertiser's phone number.
withEndDate AdWordsApp.MessageBuilder Sets the message's end date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.
withExtensionText AdWordsApp.MessageBuilder Sets the extension text shown in the ad.
withMessageText AdWordsApp.MessageBuilder Sets the message text populating the messaging app.
withMobilePreferred AdWordsApp.MessageBuilder Sets the message's device preference to mobile or clears it.
withPhoneNumber AdWordsApp.MessageBuilder Sets the advertiser's phone number that gets appended to the ad.
withSchedules AdWordsApp.MessageBuilder Sets the message scheduling.
withStartDate AdWordsApp.MessageBuilder Sets the message's start date from either an object containing year, month, and day fields, or an 8-digit string in YYYYMMDD format.

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:

TypeDescription
AdWordsApp.MessageOperation The associated message operation.

withBusinessName(businessName)

Sets the advertiser's business name. This field is required.

Arguments:

NameTypeDescription
businessName String The business name of the advertiser.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified business name.

withCountryCode(countryCode)

Sets the two character country code of the advertiser's phone number. This field is required.

Arguments:

NameTypeDescription
countryCode String The country code for the phone number.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified country code.

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:

NameTypeDescription
date Object The new message end date.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified end date.

withExtensionText(extensionText)

Sets the extension text shown in the ad. This field is required.

Arguments:

NameTypeDescription
extensionText String The extension text shown in the ad.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified extension text.

withMessageText(messageText)

Sets the message text populating the messaging app. This field is required.

Arguments:

NameTypeDescription
messageText String The message text populating the messaging app.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified message text.

withMobilePreferred(isMobilePreferred)

Sets the message's device preference to mobile or clears it. This field is optional and defaults to false.

Arguments:

NameTypeDescription
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:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified mobile preference.

withPhoneNumber(phoneNumber)

Sets the advertiser's phone number that gets appended to the ad. This field is required.

Arguments:

NameTypeDescription
phoneNumber String The phone number as a string.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified phone number.

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:

NameTypeDescription
schedules AdWordsApp.ExtensionSchedule[] The new message schedules.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified schedules.

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:

NameTypeDescription
date Object The new message start date.

Return values:

TypeDescription
AdWordsApp.MessageBuilder A message builder with the specified start date.

Send feedback about...

AdWords Scripts
AdWords Scripts
Need help? Visit our support page.