Version 4.7.6
This commit is contained in:
1 parent
8ba7d43898
commit
7b7404e741
1085 files changed
+30590
-7837
No files matched your search
+29
-2
@@ -77,6 +77,7 @@ class _Webhook extends \IPS\Node\Model
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$this->content_type = 'application/x-www-form-urlencoded';
|
||||
$this->_data['filters'] = '{}';
|
||||
$this->_data['url'] = '';
|
||||
$this->_data['events'] = '';
|
||||
@@ -91,6 +92,19 @@ class _Webhook extends \IPS\Node\Model
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'url', $this->url ?? "", TRUE ) );
|
||||
|
||||
if( \in_array($this->content_type, ['application/x-www-form-urlencoded', 'application/json']))
|
||||
{
|
||||
$selectedHeader = $this->content_type;
|
||||
$customHeader = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$selectedHeader = 'custom';
|
||||
$customHeader = $this->content_type;
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Select('webhook_content_type', $selectedHeader, TRUE , ['options' => ['application/x-www-form-urlencoded' => 'x-www-form-urlencoded', 'application/json' => 'application/json', 'custom' => 'Other'] , 'toggles'=> ['custom' => ['webhook_content_type_other'] ] ] ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text('webhook_content_type_other', $customHeader, FALSE , [], NULL, NULL, NULL, 'webhook_content_type_other' ) );
|
||||
$events = [];
|
||||
|
||||
foreach ( \IPS\Api\Webhook::getAvailableWebhooks() as $app => $hooks )
|
||||
@@ -116,8 +130,17 @@ class _Webhook extends \IPS\Node\Model
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
$values['events'] = $values['webhook_events'];
|
||||
unset( $values['webhook_events'] );
|
||||
|
||||
if( $values['webhook_content_type'] AND $values['webhook_content_type'] === 'custom' )
|
||||
{
|
||||
$values['content_type'] = $values['webhook_content_type_other'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['content_type'] = $values['webhook_content_type'];
|
||||
}
|
||||
|
||||
unset( $values['webhook_events'], $values['webhook_content_type'], $values['webhook_content_type_other'] );
|
||||
|
||||
return $values;
|
||||
}
|
||||
@@ -147,6 +170,9 @@ class _Webhook extends \IPS\Node\Model
|
||||
*/
|
||||
public static function fire( $event, $data = NULL, $filters = array() )
|
||||
{
|
||||
/* This will intentionally not call $data::apiOutput to avoid unnecessary overhead here */
|
||||
\IPS\Log::debug( print_r( array_merge(['event' => $event], ['payload' => $data], ['filters' => $filters ]) , TRUE ), 'webhook_fire_call');
|
||||
|
||||
/* Get our webhooks from cache */
|
||||
if ( !isset( \IPS\Data\Store::i()->webhooks ) )
|
||||
{
|
||||
@@ -163,7 +189,8 @@ class _Webhook extends \IPS\Node\Model
|
||||
$webhooks[ $e ][ $row['id'] ] = array(
|
||||
'key' => $row['api_key'],
|
||||
'url' => $row['url'],
|
||||
'filters' => json_decode( $row['filters'], TRUE )
|
||||
'filters' => json_decode( $row['filters'], TRUE ),
|
||||
'content_type_header' => $row['content_type']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user