text:
import 'url-search-params-polyfill'

const apiBase = 'https://app.botamp.com/api/v1/'
let api, apiKey, pageId, promise, urlParams

function apiUrl (resource, id, subResource) {
  let url = apiBase + resource

  if (id) {
    url += (`/${id}`)
  }

  if (subResource) {
    url += (`/${subResource}`)
  }

  return url
}

function setRequestHeaders () {
  api.setRequestHeader('Content-Type', 'application/vnd.api+json')
  api.setRequestHeader('Authorization', 'Basic ' + btoa(`${apiKey}:`))
  api.withCredentials = true
}

function requestBody (type, attributes) {
  return JSON.stringify({ data: { type, attributes } })
}

function contactIdKey () {
  return `botamp_${pageId}_contact_id`
}

function loadContact (contactId) {
  api.open('GET', apiUrl('contacts', contactId), true)

  api.onload = () => {
    if (api.status === 200) {
      localStorage.setItem(contactIdKey(), contactId)
    }
  }

  setRequestHeaders()
  api.send()
}

function getContactId () {
  return localStorage.getItem(contactIdKey())
}

function createContact (attributes) {
  promise = promise.then(() => {
    api.open('POST', apiUrl('contacts'))

    api.onload = () => {
      if (api.status === 201) {
        localStorage.setItem(contactIdKey(), JSON.parse(api.responseText)['data']['id'])
      }
    }

    setRequestHeaders()
    api.send(requestBody('contacts', attributes))
  })
}

function updateContact (id, attributes) {
  promise = promise.then(() => {
    api.open('PUT', apiUrl('contacts', id))

    setRequestHeaders()
    api.send(requestBody('contacts', attributes))
  })
}

function parseUrlParams () {
  const params = new URLSearchParams(window.location.search)

  urlParams = {}

  for (let pair of params.entries()) {
    urlParams[pair[0]] = pair[1]
  }

  params.delete('btp_cid')
  window.history.replaceState(null, '', `?${params}${window.location.hash}`)
}

function redirectToTaggedHref (e) {
  const href = e.target.getAttribute('href')

  if (!(e.target.tagName.toLowerCase() === 'a' && href.includes('m.me/'))) {
    return
  }

  const contactId = getContactId()

  if (contactId) {
    e.preventDefault()

    document.location.href = `${href}?ref=` + encodeURIComponent(`botamp?btp_cid=${contactId}`)
  }
}

class Botamp {
  constructor () {
    let botamp = window.botamp || []

    while (botamp.length) {
      this.push(botamp.shift())
    }

    parseUrlParams()

    window.addEventListener('click', redirectToTaggedHref, false)
  }

  push (param) {
    if (this[param[0]]) {
      this[param[0]].apply(this, param[1])
    } else {
      throw new Error(`Function '${param[0]}' does not exist.'`)
    }
  }

  load (publicApiKey) {
    apiKey = publicApiKey

    api = new XMLHttpRequest()

    promise = new Promise((resolve, reject) => {
      api.open('GET', apiUrl('me'), true)

      api.onload = () => {
        if (api.status === 200) {
          pageId = JSON.parse(api.responseText)['data']['id']

          if (urlParams['btp_cid']) {
            loadContact(urlParams['btp_cid'])
          }

          resolve()
        } else {
          reject(api.responseText)
        }
      }

      api.onerror = () => { reject() }

      setRequestHeaders()
      api.send()
    })

    promise = promise.catch(error => {
      if (error) {
        console.log(error)
      }
    })
  }

  identify () {
    if (arguments.length === 1) {
      const contactId = getContactId()

      if (contactId) {
        updateContact(contactId, arguments[0])
      } else {
        createContact(arguments[0])
      }
    } else if (arguments.length === 2) {
      updateContact(arguments[0], arguments[1])
    }
  }

  track (name, properties) {
    promise = promise.then(() => {
      api.open('POST', apiUrl('contacts', getContactId(), 'events'))

      setRequestHeaders()
      api.send(requestBody('events', {name: name, properties: properties}))
    })
  }
}

window.botamp = new Botamp()

redpajama_set_name: RedPajamaGithub


There are so many ways to explore Sri Lanka. Here's one way we like to do it, combining some of the best bits with some hidden gems.
This trip is a great way to see some of the best Sri Lanka has to offer, travelling from west to east, crossing the hills with their tea plantations and forests, spending a few days in the sublime Gal Oya National Park, hiking through Sinharaja rainforest, and finishing off with a few days relaxing on the beach.
Remember this is just a suggested itinerary – your own holiday will be tailored to exactly what you want to see and do.
Day 1: Take to the skies!
Fly from wherever you are to Sri Lanka. From the UK the best option is overnight with Sri Lankan Airlines.
Day 2: Welcome to Sri Lanka!
We will be waiting to greet you on your arrival in Colombo. Meet your chauffeur guide who will be with you for your entire trip in Sri Lanka. From here it's a beautiful 3.5 hour drive to the charming town of Kandy in the hills.
Today we will take you out to explore historic Kandy, including the Temple of the Tooth and the Royal Botanical Gardens. Kandy is known as the cultural capital of Sri Lanka and is a great town to stroll around - the old town itself is a UNESCO World Heritage Site.
Venture further east today with a 3.5 hour drive out to the remote Gal Oya National Park, and check into the amazing Gal Oya Lodge. You're in a magical place - relax and enjoy the serenity, or head out for an evening boat safari on the reservoir.
The huge reservoir here is a very special place for wildlife, and the only national park in Sri Lanka where safaris are done by boat – see wild elephants swimming across the lake, and various other animals coming to the shore to drink.
Spend a couple of days enjoying the serenity and beauty of the Gal Oya Lodge and surrounding areas. There are plenty of activities organised by the hotel, including bird walks of various lengths, a morning walk up Monkey Mountain, and setting up camera traps in the evening as part of the lodge's animal monitoring program.
Return to the hills today – this time much higher up with a 3,5 hour drive to the old British hill town of Nuwara Eliya in the heart of Sri Lanka's tea growing region. We'll take you out to a tea factory where to see tea being made before checking into your hotel. Head out to explore the town.
We will drive you about an hour out of town today for a walk in Horton Plains National Park, a beautiful area of high grasslands and cloud forests. High in the hills this is a completely different side of Sri Lanka to what you have already seen. Watch out for herds of sambar deer.
Leave the hills today as we drive you down to the Sinharaja Forest Reserve, a rainforest with some of Sri Lanka's richest biodiversity – check into your hotel and listen to the sounds of the rainforest.
Venture out for an amazing hike through Sinharaja rainforest with your guide. This UNESCO heritage site is home to an amazing array of wildlife in the jungle – including leopards – so make sure you bring your camera.
Today we will drive you 3.5 hours to spend the last few days of your holiday on the beach at Bentota. The beaches here are beautiful and there's a great selection of hotels for different budgets. Visit the turtle hatchery, do some water sports, or take a river safari on the Bentota river and lagoon.
Enjoy your final day on the beach at Bentota.
Transfer to the airport for your return flight home. If you prefer we can arrange a final night closer to the airport, for a shorter and more relaxed journey home.
Our 'Tea Plantations, Temples and Tropical Forests' itinerary includes: International flights (price based on London), accommodation, daily breakfast, transfers & drives in AC vehicle with English-speaking chauffeur guide, wildlife safaris, activities and sightseeing as indicated.