Insights Videos Blog Learning
CHEATSHEET

Pebble Scripts Cheatsheet

Getting Started with Pebble Scripts and its use in Webex Contact Center.

Pebble templates are used in Webex Contact Center's Flow Designer to control logic, manipulate data, and personalize customer interactions. Whether you're setting routing conditions, formatting phone numbers, or working with estimated wait times, Pebble helps you keep flows flexible and dynamic — without writing external code.

This cheatsheet gives you a quick reference of the most common patterns, filters, and techniques to get the job done efficiently inside Flow Designer.

Where Pebble Templates Are Used in Webex Contact Center:

Set Variables Dynamically: For example, converting estimated wait time from milliseconds to a readable format for text-to-speech.

Conditional Logic in Branch Nodes: Route based on available skills, ANI, DNIS, or any custom data.

Data Formatting and Cleanup: Use built-in filters to transform phone numbers, names, dates, and more.

Working with API Responses: Manipulate data from HTTP requests or system lookups (JSON parsing, string handling).

Pebble Basics

Pebble templates use a clean and expressive syntax for working with data, setting conditions, and controlling flow logic. These are the key building blocks you'll use across your Webex Contact Center flows.

Syntax Overview

  • {{ variable }} — Output the value of a variable.
  • {% if condition %}...{% endif %} — Conditional logic blocks.
  • {% for item in items %}...{% endfor %} — Loop through lists, arrays, or maps.
  • {# This is a comment #} — Comment line, ignored during execution.

Common Variables in Webex CC Flows

Variable Description Example Usage
contact Contact object containing customer-related information. {{ contact.ani }} — Caller's phone number.
task Task object with interaction details like channel type. {{ task.mediaType }} — E.g., telephony or chat.
user User (agent) object with agent-related information. {{ user.firstName }} — Agent's first name.

Control Structures

If Statements

{% if contact.mediaType == "telephony" %}
  Handle voice call
{% elseif contact.mediaType == "chat" %}
  Handle chat
{% else %}
  Handle other channels
{% endif %}

Loops

{% for skill in agent.skills %}
  {{ skill.name }}
{% endfor %}

Pebble Filters & Functions Reference

Pebble templates provide a range of built-in filters and functions to transform, clean, and process data directly within your Webex Contact Center flows. These are some of the most commonly used ones:

  • upper(string) — Convert text to uppercase.
    Example: {% raw %}{{ contact.firstName | upper }}{% endraw %}
  • lower(string) — Convert text to lowercase.
    Example: {% raw %}{{ contact.lastName | lower }}{% endraw %}
  • trim(string) — Remove whitespace from the beginning and end of a string.
    Example: {% raw %}{{ user.input | trim }}{% endraw %}
  • date(timestamp, format) — Format dates and times.
    Example: {% raw %}{{ now() | date("yyyy-MM-dd'T'HH:mm:ss") }}{% endraw %}
  • split(string, delimiter) — Split a string into a list.
    Example: {% raw %}{{ email | split('@') }}{% endraw %}
  • replace(string, old, new) — Replace part of a string.
    Example: {% raw %}{{ phone | replace("+", "") }}{% endraw %}
  • contains(collection, value) — Check if a list or map contains a specific value.
    Example: {% raw %}{{ ["410", "443"] contains contact.areaCode }}{% endraw %}
  • slice(string, start, end) — Extract a substring by position.
    Example: {% raw %}{{ ani | slice(0,3) }}{% endraw %} — First three digits.
  • length(string/list/map) — Get the length of a string, list, or map.
    Example: {% raw %}{{ agent.skills | length }}{% endraw %}
  • number_format(number, decimals) — Format a number with specified decimal places.
    Example: {% raw %}{{ 1234.5678 | number_format(2) }}{% endraw %} → 1234.57

Common Pebble Expressions (with Examples)

Here are some practical Pebble expression patterns that you are likely to use often in Webex Contact Center flows. These cover typical needs like string manipulation, phone number handling, time formatting, and list matching.

Expression Description / Usage
{% raw %}{{ now() | date("yyyy-MM-dd", existingFormat="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timeZone="America/New_York") }}{% endraw %} Format the current date and control time zone output. Useful for time-based routing, greetings, or SLA decisions.
{% raw %}{% if (NewPhoneContact.ANI.length == 12) and (NewPhoneContact.ANI == '123456789012') %}{{ NewPhoneContact.ANI | slice(8,12) }}{% raw %}{% else %}0{% endif %}{% endraw %} Conditional slicing of ANI based on length. Example: grabbing the last few digits for queue selection or routing logic.
{% raw %}{{ ["410", "443", "667"] contains Caller_Area }}{% endraw %} Check if a variable (like a caller's area code) exists in a predefined list. Helpful for area-based routing or group identification.
{% raw %}{{ email | split('@') | last }}{% endraw %} Extract the domain part of an email address. Useful for matching partner or customer domains.
{% raw %}{{ callbackNumber | replace("+", "") }}{% endraw %} Remove the + from phone numbers before processing or validation.
{% raw %}{{ stringToSplit | split("|") | first }}{% endraw %} Get the first element from a pipe-delimited string. Useful for parsing lists passed in as single strings.
{% raw %}{{ varName | trim }}{% endraw %} Remove leading and trailing spaces from strings. Helps avoid whitespace issues with user input or API responses.
{% raw %}{{ GetQueueInfo.EWT | date("HH:mm:ss") }}{% endraw %} Convert Estimated Wait Time (in milliseconds) to a readable time string for TTS playback or announcements.

Common Use Cases

These examples show how to apply Pebble templates in real-world Webex Contact Center flows. They combine control structures and filters to help you handle common routing and personalization scenarios.

Dynamic Queue Selection

{% raw %}{% if contact.skillNeeded in availableSkills %}
  {{ "route_to_skill" }}
{% else %}
  {{ "route_to_default" }}
{% endif %}{% endraw %}

Use case: Route the contact to a specific queue based on the required skill. If the skill isn't available, use a default queue instead.

Personalized Greeting Based on Time of Day

{% raw %}{% if hour < 12 %}
  Good morning
{% elseif hour < 18 %}
  Good afternoon
{% else %}
  Good evening
{% endif %}, {{ contact.firstName }}{% endraw %}

Use case: Generate a friendly greeting for TTS or chat, customized by time of day and the customer's first name.

Phone Number Cleanup Before Validation

{% raw %}{{ callbackNumber | replace("+", "") | trim }}{% endraw %}

Use case: Clean up phone numbers by removing + signs and trimming any extra spaces before validating or passing to downstream systems.

Format Estimated Wait Time for TTS Playback

{% raw %}{{ GetQueueInfo.EWT | date("HH:mm:ss") }}{% endraw %}

Use case: Convert Estimated Wait Time (EWT) from milliseconds to a TTS-friendly string like "00:02:35" for use in announcements.

Check for Known Caller Area Codes

{% raw %}{% if ["410", "443", "667"] contains contact.areaCode %}
  {{ "priority_routing" }}
{% raw %}{% else %}
  {{ "standard_routing" }}
{% endif %}{% endraw %}

Use case: Apply priority routing if the caller's area code matches one of the preferred regions.

Common Mistakes (and How to Avoid Them)

Pebble templates are straightforward for basic use, but there are a few common pitfalls that can trip up even experienced users. Here are the most frequent mistakes — and how to avoid them.

Type Mismatch: first Returns a Char, Not a String

Problem: Using first on a string returns a character (char), not a string. Comparing it directly to a string value may fail unexpectedly.

Incorrect:

{% raw %}{{ my_string | first == "a" ? "Yes" : "No" }}{% endraw %}

Correct:

{% raw %}{{ my_string | slice(0,1) == "a" ? "Yes" : "No" }}{% endraw %}

length Does Not Work on JSON Objects

Problem: The length filter works only on strings, lists, or maps — not directly on JSON objects.

Incorrect Example:

{% raw %}{{ my_json_object | length }}{% endraw %}

Workaround (if JSONPath/JPath is supported):

{% raw %}{{ $.result[].length() }}{% endraw %}

This approach has been observed to work in Webex CC flows but may not be officially documented.


No Built-in Random Function

Problem: Pebble does not have a built-in random() function for selecting random values.

Workarounds:

  • Use an external API call to generate a random number and pass it into the flow.
  • Predefine a list of options and select one based on another numeric input (e.g., GetQueueInfo.EWT mod list.length).

Date and Time Formatting Confusion

Problem: Variables like GetQueueInfo.EWT return values in milliseconds. Directly outputting these values is not TTS-friendly or readable.

Incorrect:

{% raw %}{{ GetQueueInfo.EWT }}{% endraw %}

Correct (Formatted for speech):

{% raw %}{{ GetQueueInfo.EWT | date("HH:mm:ss") }}{% endraw %}

Special Characters and Multi-line String Storage Issues

Problem: Some special characters (quotes, slashes, tabs, newlines) may not store correctly if added directly through the Flow Designer UI.

Solutions:

  • Use URL encoding to safely store complex strings.
  • Use the Global Variables API to set these values if the UI blocks direct input.
  • Apply replace() or url_encode() filters if available in your Pebble environment.

Best Practices & Debugging Tips

Following these best practices can help you write cleaner, more maintainable Pebble templates and reduce troubleshooting time in your Webex Contact Center flows.

Best Practices

  1. Validate input data before using it — check if variables exist or are not null.
  2. Use meaningful and consistent variable names for easier readability and debugging.
  3. Comment your logic clearly, especially for complex conditions or loops.
  4. Break down large expressions into smaller steps by assigning intermediate values to variables.
  5. Keep your logic simple — avoid deeply nested conditions where possible.

Debugging Tips

  • Use Flow Designer's debug mode to inspect variable values and understand flow execution paths.
  • Log important variable values at different stages if supported by your flow setup (e.g., using log() or assigned debug variables).
  • Test edge cases with sample data — include empty strings, nulls, special characters, and unexpected inputs.
  • Validate Pebble syntax using simple test flows before deploying into production logic.

Closing Thoughts

This cheatsheet covers common Pebble template patterns, filters, functions, and tips that are relevant for daily use inside Webex Contact Center flows. Remember, this is meant as a quick reference — it doesn't replace the full documentation.

For deeper understanding of Pebble template capabilities and more advanced usage, refer to the official Pebble Templates documentation: https://pebbletemplates.io/wiki/home/.

Feel free to expand on these patterns based on your own project needs. Happy flow building!