sms.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { EnumTicketArticleSenderName } from '#shared/graphql/types.ts'
  3. import type {
  4. TicketArticleAction,
  5. TicketArticleActionPlugin,
  6. TicketArticleType,
  7. } from './types.ts'
  8. const actionPlugin: TicketArticleActionPlugin = {
  9. order: 300,
  10. addActions(ticket, article) {
  11. if (
  12. article.sender?.name !== EnumTicketArticleSenderName.Customer ||
  13. article.type?.name !== 'sms'
  14. )
  15. return []
  16. const action: TicketArticleAction = {
  17. apps: ['mobile', 'desktop'],
  18. label: __('Reply'),
  19. name: 'sms',
  20. icon: 'reply',
  21. view: {
  22. agent: ['change'],
  23. },
  24. perform(ticket, article, { openReplyForm }) {
  25. const from = article.from?.raw
  26. const articleData = {
  27. articleType: 'sms',
  28. to: from ? [from] : [],
  29. inReplyTo: article.messageId,
  30. }
  31. openReplyForm(articleData)
  32. },
  33. }
  34. return [action]
  35. },
  36. addTypes(ticket) {
  37. const descriptionType = ticket.createArticleType?.name
  38. if (descriptionType !== 'sms') return []
  39. const type: TicketArticleType = {
  40. apps: ['mobile', 'desktop'],
  41. value: 'sms',
  42. label: __('Sms'),
  43. buttonLabel: __('Add sms'),
  44. icon: 'message',
  45. view: {
  46. agent: ['change'],
  47. },
  48. internal: false,
  49. contentType: 'text/plain',
  50. fields: {
  51. body: {
  52. required: true,
  53. validation: 'length:1,160',
  54. },
  55. to: {},
  56. },
  57. options: {
  58. recipientContact: 'phone',
  59. },
  60. editorMeta: {
  61. footer: {
  62. maxlength: 160,
  63. warningLength: 30,
  64. },
  65. },
  66. performReply(ticket) {
  67. const { preferences } = ticket
  68. return {
  69. to: [preferences?.sms?.originator || preferences?.sms?.From],
  70. }
  71. },
  72. }
  73. return [type]
  74. },
  75. }
  76. export default actionPlugin