*/ private const COLORS = array( 'critical' => 0xE11D48, 'out_of_stock' => 0xE11D48, 'warning' => 0xF59E0B, 'low_stock' => 0xF59E0B, 'po_overdue' => 0xF59E0B, ); /** * Send a message. * * @param array $message Message. * @param array $config Channel config. * @return true|\WP_Error */ public function send( array $message, array $config ) { $lines = array(); if ( '' !== (string) ( $message['intro'] ?? '' ) ) { $lines[] = (string) $message['intro']; } foreach ( $this->item_lines( $message ) as $line ) { $lines[] = '• ' . $line; } return $this->post_json( (string) $config['webhook_url'], array( 'username' => 'ProfitEngine', // Never ping @everyone/@here or roles from product names. 'allowed_mentions' => array( 'parse' => array() ), 'embeds' => array( array( 'title' => mb_substr( (string) $message['title'], 0, 250 ), 'description' => mb_substr( implode( "\n", $lines ), 0, 4000 ), 'url' => esc_url_raw( (string) $message['url'] ), 'color' => self::COLORS[ (string) $message['event'] ] ?? 0x12B48A, 'footer' => array( 'text' => (string) $message['site'] ), 'timestamp' => gmdate( 'c' ), ), ), ) ); } }