Docs »

Plugins »

Extension Points »

Bot Event

Name: Bot Event
Identifier (ID): devblocks.event

Manifest


		<extension point="devblocks.event">
			<id>example.bot.event</id>
			<name>Example bot event</name>
			<class>
				<file>api/events/example.php</file>
				<name>Event_Example</name>
			</class>
			<params>
				<param key="contexts">
					<value>
						<data key="cerberusweb.contexts.app"/>
						<data key="cerberusweb.contexts.group"/>
						<data key="cerberusweb.contexts.role"/>
						<data key="cerberusweb.contexts.worker"/>
					</value>
				</param>
				<param key="options">
					<value>
						<data key="visibility"/>
					</value>
				</param>
			</params>
		</extension>

Params

  • contexts: This event is available for bots owned by one of these contexts.

  • These options configure the event:

    • visibility: The event has public/private variants. This is uncommon.

Code



class Event_Example extends Extension_DevblocksEvent {
	const ID = 'example.bot.event';

	/**
	 * 
	 * 
	 * @return Model_DevblocksEvent
	 */
	function generateSampleEventModel(Model_TriggerEvent $trigger) {
		$actions = [];
		
		return new Model_DevblocksEvent(
			static::ID,
			[
				'key' => 'value',
				'actions' => &$actions,
			]
		);
	}
	
	public function renderEventParams(Model_TriggerEvent $trigger=null) {
		
	}
	
	/**
	 * @param array $event_params
	 * @param string $error
	 * @return boolean
	 */
	public function prepareEventParams(Model_TriggerEvent $behavior=null, &$new_params, &$error) {
		$error = null;
		return true;
	}

	public function setEvent(Model_DevblocksEvent $event_model=null, Model_TriggerEvent $trigger=null) {
		$labels = [];
		$values = [];
		
		/**
		 * Behavior
		 */
		
		$merge_labels = [];
		$merge_values = [];
		CerberusContexts::getContext(CerberusContexts::CONTEXT_BEHAVIOR, $trigger, $merge_labels, $merge_values, null, true);

			// Merge
			CerberusContexts::merge(
				'behavior_',
				'',
				$merge_labels,
				$merge_values,
				$labels,
				$values
			);
		
		// [TODO] Register key/values from the event
		
		//@$value = $event_model->params['key'];
		//$labels['key'] = 'Key';
		//$values['key'] = $value;
		
		//$values['_actions'] =& $event_model->params['actions'];
		
		/**
		 * Return
		 */

		$this->setLabels($labels);
		$this->setValues($values);
	}
	
	public function renderSimulatorTarget($trigger, $event_model) {
		
	}
	
	function getValuesContexts($trigger) {
		$vals = array(
			'behavior_id' => [
				'label' => 'Behavior',
				'context' => CerberusContexts::CONTEXT_BEHAVIOR,
			],
			'behavior_bot_id' => [
				'label' => 'Bot',
				'context' => CerberusContexts::CONTEXT_BOT,
			],
		);
		
		$vars = parent::getValuesContexts($trigger);
		
		$vals_to_ctx = array_merge($vals, $vars);
		DevblocksPlatform::sortObjects($vals_to_ctx, '[label]');
		
		return $vals_to_ctx;
	}
	
	public function getConditionExtensions(Model_TriggerEvent $trigger) {
		$labels = $this->getLabels($trigger);
		$types = $this->getTypes();
		
		$labels['example_condition'] = 'Example Condition';
		$types['example_condition'] = null;
		
		$conditions = $this->_importLabelsTypesAsConditions($labels, $types);
		
		return $conditions;
	}
	
	public function renderConditionExtension($token, $as_token, $trigger, $params=[], $seq=null) {
		$tpl = DevblocksPlatform::services()->template();
		$tpl->assign('params', $params);

		if(!is_null($seq))
			$tpl->assign('namePrefix','condition'.$seq);
		
		switch($as_token) {
			case 'example_condition':
				// [TODO] Render condition configuration template
				break;
		}
	}
	
	public function runConditionExtension($token, $as_token, $trigger, $params, DevblocksDictionaryDelegate $dict) {
		$pass = true;
		
		switch($as_token) {
			case 'example_condition':
				// [TODO] Implement condition logic
				$pass = true;
				break;
				
			default:
				$pass = false;
				break;
		}
		
		return $pass;
	}
	
	public function getActionExtensions(Model_TriggerEvent $trigger) {
		$actions =
			[
				'example_action' => array('label' => 'Example Behavior Action'),
			]
		;
		
		return $actions;
	}

	public function renderActionExtension($token, $trigger, $params=[], $seq=null) {
		$tpl = DevblocksPlatform::services()->template();
		$tpl->assign('params', $params);

		if(!is_null($seq))
			$tpl->assign('namePrefix','action'.$seq);

		$labels = $this->getLabels($trigger);
		$tpl->assign('token_labels', $labels);
			
		switch($token) {
			case 'example_action':
				// [TODO] Render action configuration template
				//$tpl->display('devblocks:example.plugin::events/action_example.tpl');
				break;
		}
	}

	protected function simulateActionExtension($token, $trigger, $params, DevblocksDictionaryDelegate $dict) {
		$out = null;
		
		switch($token) {
			case 'example_action':
				// [TODO] Output something
				$out = sprintf(">>> Output\n");
				break;
		}
		
		return $out;
	}
	
	public function runActionExtension($token, $trigger, $params, DevblocksDictionaryDelegate $dict) {
		switch($token) {
			case 'example_action':
				// [TODO] Do something
				break;
		}
	}
};


Extensions

After message sent from group member event.mail.after.sent.group
After message sent from worker event.mail.after.sent
Before composing a message reply event.mail.reply.pre.ui.worker
Before composing a new message event.mail.compose.pre.ui.worker
Before message sent by group member event.mail.sent.group
Before message sent by worker event.mail.before.sent
Chat with portal visitor event.message.chat.portal
Chat with worker event.message.chat.worker
Custom API request event.api.custom_request
Dashboard get metric for widget event.dashboard.widget.get_metric
Dashboard render widget event.dashboard.widget.render
Data query datasource event.data.query.datasource
Filter new incoming message event.mail.received.app
Form interaction event.form.interaction.worker
Get chat interactions for worker event.interactions.get.worker
Handle chat interaction with portal visitor event.interaction.chat.portal
Handle chat interaction with worker event.interaction.chat.worker
New JIRA issue wgmjira.event.issue.created
New comment on JIRA issue wgmjira.event.issue.commented
New comment on ticket in group event.comment.ticket.group
New contact registered in Support Center event.contact.registered.sc
New message added to ticket in group event.mail.received.group
New message added to ticket event.mail.received
New message on a watched ticket event.mail.received.watcher
New notification for me event.notification.received.worker
New status on JIRA issue wgmjira.event.issue.status.changed
New task created event.task.created.worker
Record changed event.record.changed
Record commented on event.comment.created.worker
Record custom behavior on JIRA issue event.macro.jira_issue
Record custom behavior on JIRA project event.macro.jira_project
Record custom behavior on bot event.macro.bot
Record custom behavior on calendar event event.macro.calendar_event
Record custom behavior on calendar event.macro.calendar
Record custom behavior on call event.macro.call
Record custom behavior on contact event.macro.contact
Record custom behavior on domain event.macro.domain
Record custom behavior on email address event.macro.address
Record custom behavior on feed item event.macro.feeditem
Record custom behavior on group event.macro.group
Record custom behavior on knowledgebase article event.macro.kb_article
Record custom behavior on message event.macro.message
Record custom behavior on notification event.macro.notification
Record custom behavior on opportunity event.macro.crm.opportunity
Record custom behavior on organization event.macro.org
Record custom behavior on reminder event.macro.reminder
Record custom behavior on sensor event.macro.sensor
Record custom behavior on server event.macro.server
Record custom behavior on task event.macro.task
Record custom behavior on ticket event.macro.ticket
Record custom behavior on time tracking entry event.macro.timetracking
Record custom behavior on worker event.macro.worker
Record editor opened event.ui.card.editor.opened.worker
Record worklist rendered event.ui.worklist.render.worker
Recurrent behavior event.behavior.recurrent
Respond to Ajax HTTP request event.ajax.request
Ticket assigned in group event.mail.assigned.group
Ticket closed in group event.mail.closed.group
Ticket moved in group event.mail.moved.group
Ticket profile viewed by a worker event.ticket.viewed.worker
Webhook received event.webhook.received
[DEPRECATED] During a message reply event.mail.reply.during.ui.worker