<commit_before>// TODO
// Add card support to Telegram

import url from 'url'

export default data => [
  {
    on: 'facebook',
    template_type: 'generic',
    elements: data.items.map(card => ({
      title: card.title,
      image_url: card.image ? url.resolve(data.BOT_URL, card.image) : null,
      subtitle: card.subtitle,
      buttons: (card.actions || []).map(a => {
        if (a.action === 'Say something') {
          return {
            type: 'postback',
            title: a.title,
            payload: a.title
          }
        } else if (a.action === 'Open URL') {
          return {
            type: 'web_url',
            title: a.title,
            url: a.url
          }
        }
      })
    })),

    typing: data.typing
  },
  {
    on: 'webchat',
    type: 'carousel',
    text: ' ',
    elements: data.items.map(card => ({
      title: card.title,
      picture: card.image ? url.resolve(data.BOT_URL, card.image) : null,
      subtitle: card.subtitle,
      buttons: (card.actions || []).map(a => {
        if (a.action === 'Say something') {
          return {
            title: a.title,
            payload: a.title
          }
        } else if (a.action === 'Open URL') {<commit_msg>fix(core): remove 'buttons' fields when actions empty (ref #690) (#1000)<commit_after>// TODO
// Add card support to Telegram

import url from 'url'

export default data => [
  {
    on: 'facebook',
    template_type: 'generic',
    elements: data.items.map(card => {
      const buttons = (card.actions || []).map(a => {
        if (a.action === 'Say something') {
          return {
            type: 'postback',
            title: a.title,
            payload: a.title
          }
        } else if (a.action === 'Open URL') {
          return {
            type: 'web_url',
            title: a.title,
            url: a.url
          }
        }
      })
      const buttonsWrapper = card.actions ? { buttons } : {}

      return {
        title: card.title,
        image_url: card.image ? url.resolve(data.BOT_URL, card.image) : null,
        subtitle: card.subtitle,
        ...buttonsWrapper
      }
    }),

    typing: data.typing
  },
  {
    on: 'webchat',
    type: 'carousel',
    text: ' ',
    elements: data.items.map(card => ({
      title: card.title,
      picture: card.image ? url.resolve(data.BOT_URL, card.image) : null,
      subtitle: card.subtitle,
      buttons: (card.actions || []).map(a => {
        if (a.action === 'Say something') {
          return {
            title: a.title,
            payload: a.title
          }
        } else if (a.action === 'Open URL') {
{'fraction_non_alphanumeric': 0.1518504387638306, 'fraction_numerical': 0.002670736360167875, 'mean_word_length': 1.6673448626653102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2142978', 'n_tokens_mistral': 830, 'n_tokens_neox': 817, 'n_words': 196}