Skip to content

Commit

Permalink
Rest API bot response type improvement
Browse files Browse the repository at this point in the history
Now you can execute another trigger if Rest API call takes long time. In case of php-resque is making request and request takes long time
  • Loading branch information
remdex committed Jan 4, 2022
1 parent d311665 commit ac528a6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lhc_web/design/defaulttheme/js/react/build/all.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,15 @@ class NodeTriggerActionRestAPI extends Component {
</div>
</div>
<div className="col-6">
<label>Trigger to execute before default</label>
<label>Trigger to execute before default <i className="material-icons" title="Usefull for logging purposes to track full path of navigation. Use `Log action` response type. This trigger is executed only if default trigger is executed.">info</i></label>
<NodeTriggerList onSetPayload={(e) => this.onchangeAttr({'path':['rest_api_method_output','default_trigger_alt'],'value':e})} payload={this.props.action.getIn(['content','rest_api_method_output','default_trigger_alt'])} />
</div>
<div className="col-12">
<div className="form-group">
<label>If your Rest API takes long time and visitor writes a message while it's still hapenning, you can send a custom trigger to execute. E.g this trigger can write that we are still processing your request.</label>
<NodeTriggerList enableAction={true} payload_action_id={this.props.action.getIn(['content','rest_api_method_output','long_taking_action_id'])} onSetPayloadActionId={(e) => this.onchangeAttr({'path':['rest_api_method_output','long_taking_action_id'],'value':e})} onSetPayload={(e) => this.onchangeAttr({'path':['rest_api_method_output','long_taking_trigger'],'value':e})} payload={this.props.action.getIn(['content','rest_api_method_output','long_taking_trigger'])} />
</div>
</div>
</div>

<div className="row">
Expand Down
23 changes: 23 additions & 0 deletions lhc_web/lib/core/lhgenericbot/lhgenericbotworkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,29 @@ public static function processEvent($chatEvent, & $chat, $params = array()) {
}

} elseif (isset($eventData['content']['type']) && $eventData['content']['type'] == 'rest_api') {

if (isset($eventData['content']['action']['content']['rest_api_method_output']['long_taking_trigger']) && is_numeric($eventData['content']['action']['content']['rest_api_method_output']['long_taking_trigger'])) {

$trigger = erLhcoreClassModelGenericBotTrigger::fetch($eventData['content']['action']['content']['rest_api_method_output']['long_taking_trigger']);

if ($trigger instanceof erLhcoreClassModelGenericBotTrigger) {

$paramsTrigger = array();

if (isset($params['msg'])) {
$paramsTrigger['args']['msg'] = $params['msg'];
}

$paramsTrigger['args']['msg_text'] = $payload;

if (isset($eventData['content']['action']['content']['rest_api_method_output']['long_taking_action_id']) && $eventData['content']['action']['content']['rest_api_method_output']['long_taking_action_id'] != '') {
$paramsTrigger['trigger_action_id'] = $eventData['content']['action']['content']['rest_api_method_output']['long_taking_action_id'];
}

erLhcoreClassGenericBotWorkflow::processTrigger($chat, $trigger, true, $paramsTrigger);
}
}

// Rest API in progress
// Ignore any customer request for a while
$keepEvent = true;
Expand Down
2 changes: 1 addition & 1 deletion lhc_web/modules/lhrestapi/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
},
{
"name": "prefill_fields",
"description": "What fields to prefill E.g messages_statistic,subject, link, time_created_front, department_name, plain_user_name, product_name, n_official, n_off_full, wait_time_pending, wait_time_seconds, cls_time_front, tatus_sub_sub, can_edit_chat, unread_time",
"description": "What fields to prefill E.g messages_statistic, subject, link, time_created_front, department_name, plain_user_name, product_name, n_official, n_off_full, wait_time_pending, wait_time_seconds, cls_time_front, tatus_sub_sub, can_edit_chat, unread_time, chat_actions",
"required": false,
"type": "string",
"in": "query"
Expand Down

0 comments on commit ac528a6

Please sign in to comment.