123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { EnumChannelArea } from '#shared/graphql/types.ts'
- import { i18n } from '#shared/i18n.ts'
- import type { TicketChannelPlugin } from './types.ts'
- import type { TicketById } from '../../types.ts'
- const ticketChannelPlugin: TicketChannelPlugin = {
- area: EnumChannelArea.WhatsAppBusiness,
- channelAlert(ticket: TicketById) {
- const lastWhatsappTimestamp =
- ticket.preferences?.whatsapp?.timestamp_incoming
-
- if (
- !lastWhatsappTimestamp ||
- /^(closed|merged|removed)$/.test(ticket.state.name)
- )
- return null
-
- const timeWindowEnd = new Date(lastWhatsappTimestamp * 1000)
- timeWindowEnd.setHours(timeWindowEnd.getHours() + 24)
-
- if (timeWindowEnd <= new Date()) {
- return {
- text: __(
- 'The 24 hour customer service window is now closed, no further WhatsApp messages can be sent.',
- ),
- variant: 'danger',
- }
- }
-
- return {
- text: __(
- 'You have a 24 hour window to send WhatsApp messages in this conversation. The customer service window closes %s.',
- ),
- textPlaceholder: i18n.relativeDateTime(timeWindowEnd.toString()),
- variant: 'warning',
- }
- },
- }
- export default ticketChannelPlugin
|