All files / src/flow/actions say_msg.ts

100% Statements 67/67
66.66% Branches 8/12
100% Functions 3/3
100% Lines 67/67

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68132x 2x 2x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 6x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 2x 2x 6x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 11x 11x 11x 11x 132x 132x 132x 132x 132x 132x 132x  
import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FormData, FlowTypes } from '../types';
import { Node, SayMsg } from '../../store/flow-definition';
import { renderAudioPlayer } from './audio-player';
import { renderClamped, renderHighlightedText } from '../utils';
 
export const say_msg: ActionConfig = {
  name: 'Say Message',
  group: ACTION_GROUPS.send,
  flowTypes: [FlowTypes.VOICE],
  render: (_node: Node, action: SayMsg) => {
    return html`
      ${renderClamped(
        renderHighlightedText(action.text || '', true),
        action.text || ''
      )}
      ${action.audio_url
        ? html`<div style="margin-top: 0.5em;">
            ${renderAudioPlayer(action.audio_url)}
          </div>`
        : null}
    `;
  },
  form: {
    text: {
      type: 'textarea',
      label: 'Message',
      required: true,
      evaluated: true,
      placeholder: 'Enter message to speak...',
      maxLength: 10000,
      minHeight: 80
    },
    audio_url: {
      type: 'media',
      label: 'Recording',
      required: false,
      accept: 'audio/*',
      optionalLink: 'Add a recording'
    }
  },
  layout: ['text', 'audio_url'],
  toFormData: (action: SayMsg) => {
    return {
      uuid: action.uuid,
      text: action.text || '',
      audio_url: action.audio_url || ''
    };
  },
  fromFormData: (data: FormData) => {
    const result: any = {
      uuid: data.uuid,
      type: 'say_msg',
      text: data.text || ''
    };
    if (data.audio_url && data.audio_url.trim() !== '') {
      result.audio_url = data.audio_url.trim();
    }
    return result as SayMsg;
  },
  sanitize: (formData: FormData): void => {
    if (formData.text && typeof formData.text === 'string') {
      formData.text = formData.text.trim();
    }
  },
  localizable: ['text', 'audio_url']
};