PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.1.33
OttoKit: All-in-One Automation Platform v1.1.33
1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Integrations / support-genix / actions / reply-to-ticket.php
suretriggers / src / Integrations / support-genix / actions Last commit date
change-ticket-status.php 2 months ago create-ticket.php 2 months ago reply-to-ticket.php 2 months ago
reply-to-ticket.php
167 lines
1 <?php
2 /**
3 * ReplyToTicketSupportGenix.
4 * php version 5.6
5 *
6 * @category ReplyToTicketSupportGenix
7 * @package SureTriggers
8 * @author BSF <username@example.com>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link https://www.brainstormforce.com/
11 * @since 1.0.0
12 */
13
14 namespace SureTriggers\Integrations\SupportGenix\Actions;
15
16 use Exception;
17 use Mapbd_wps_ticket;
18 use Mapbd_wps_ticket_reply;
19 use SureTriggers\Integrations\AutomateAction;
20 use SureTriggers\Integrations\SupportGenix\SupportGenix;
21 use SureTriggers\Traits\SingletonLoader;
22
23 /**
24 * ReplyToTicketSupportGenix
25 */
26 class ReplyToTicketSupportGenix extends AutomateAction {
27
28 use SingletonLoader;
29
30 /**
31 * Integration type.
32 *
33 * @var string
34 */
35 public $integration = 'SupportGenix';
36
37 /**
38 * Action name.
39 *
40 * @var string
41 */
42 public $action = 'reply_to_ticket_support_genix';
43
44 /**
45 * Register action.
46 *
47 * @param array $actions actions.
48 * @return array
49 */
50 public function register( $actions ) {
51 $actions[ $this->integration ][ $this->action ] = [
52 'label' => __( 'Reply to Ticket', 'suretriggers' ),
53 'action' => $this->action,
54 'function' => [ $this, 'action_listener' ],
55 ];
56
57 return $actions;
58 }
59
60 /**
61 * Action listener.
62 *
63 * @param int $user_id User ID.
64 * @param int $automation_id Automation ID.
65 * @param array $fields Fields.
66 * @param array $selected_options Selected options.
67 *
68 * @return array
69 * @throws Exception Exception.
70 */
71 public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
72 if ( ! class_exists( 'Mapbd_wps_ticket' ) || ! class_exists( 'Mapbd_wps_ticket_reply' ) ) {
73 return [
74 'status' => 'error',
75 'message' => __( 'Support Genix plugin is not installed or active.', 'suretriggers' ),
76 ];
77 }
78
79 $ticket_id = isset( $selected_options['ticket_id'] ) ? (int) $selected_options['ticket_id'] : 0;
80 $reply_text = isset( $selected_options['reply_text'] ) ? wp_kses_post( $selected_options['reply_text'] ) : '';
81 $replied_by_type = isset( $selected_options['replied_by_type'] ) ? sanitize_text_field( $selected_options['replied_by_type'] ) : 'A';
82 $replied_by = isset( $selected_options['replied_by'] ) ? (int) $selected_options['replied_by'] : 0;
83 $is_private = isset( $selected_options['is_private'] ) && 'Y' === $selected_options['is_private'] ? 'Y' : 'N';
84
85 if ( $ticket_id <= 0 || empty( $reply_text ) ) {
86 return [
87 'status' => 'error',
88 'message' => __( 'Ticket ID and reply text are required.', 'suretriggers' ),
89 ];
90 }
91
92 if ( ! in_array( $replied_by_type, [ 'A', 'U', 'G' ], true ) ) {
93 $replied_by_type = 'A';
94 }
95
96 if ( 'A' === $replied_by_type ) {
97 $replied_by = SupportGenix::resolve_agent_id( $replied_by );
98 if ( $replied_by <= 0 ) {
99 return [
100 'status' => 'error',
101 'message' => __( 'Could not resolve an agent user to post the reply as.', 'suretriggers' ),
102 ];
103 }
104 } elseif ( 'U' === $replied_by_type ) {
105 if ( $replied_by <= 0 || ! get_userdata( $replied_by ) ) {
106 return [
107 'status' => 'error',
108 'message' => __( 'A valid user id is required when replying as User.', 'suretriggers' ),
109 ];
110 }
111 }
112
113 /**
114 * Reply entity returned by the Support Genix plugin.
115 *
116 * @var object|null $reply_obj
117 */
118 $reply_obj = null;
119 /**
120 * Ticket entity returned by the Support Genix plugin.
121 *
122 * @var object|null $ticket
123 */
124 $ticket = null;
125
126 try {
127 $result = Mapbd_wps_ticket_reply::AddReply(
128 $ticket_id,
129 $reply_text,
130 $replied_by,
131 $replied_by_type,
132 $is_private,
133 [],
134 $reply_obj,
135 $ticket
136 );
137 } catch ( Exception $e ) {
138 return [
139 'status' => 'error',
140 'message' => $e->getMessage(),
141 ];
142 }
143
144 if ( ! $result ) {
145 return [
146 'status' => 'error',
147 'message' => __( 'Support Genix rejected the reply. The ticket may not exist or the user may not have permission to reply.', 'suretriggers' ),
148 ];
149 }
150
151 $reply_id = null;
152 if ( ! empty( $reply_obj ) && is_object( $reply_obj ) && property_exists( $reply_obj, 'reply_id' ) ) {
153 $reply_id = $reply_obj->reply_id;
154 }
155
156 return [
157 'status' => 'success',
158 'ticket_id' => $ticket_id,
159 'reply_id' => $reply_id,
160 'replied_by' => $replied_by,
161 'replied_by_type' => $replied_by_type,
162 ];
163 }
164 }
165
166 ReplyToTicketSupportGenix::get_instance();
167