UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.61 kB
const {sendMessageZalo}=require("../../libs/utils"); async function zaloSendMessageHandler($flowState_id_app$$,$node$$,$payload_receivers$$,$abortSignal$$){const $nodeInstanceId$$=`${$flowState_id_app$$.instanceId}-${$node$$.id}`;if($abortSignal$$.aborted)throw Logger.info(`[${$nodeInstanceId$$}] pushNotification node aborted before logging.`),new DOMException("Aborted by signal","AbortError");$flowState_id_app$$=$flowState_id_app$$.flowDefinition.id_app;const $template_id$$=$node$$?.data?.templateId;if(!$template_id$$)throw"Kh\u00f4ng c\u00f3 zalo template"; $payload_receivers$$.forEach||($payload_receivers$$=[$payload_receivers$$]);$payload_receivers$$=$payload_receivers$$.filter($r$$=>$r$$.recipientId||$r$$.dien_thoai||$r$$.phone||$r$$.phone_number);$payload_receivers$$.forEach($r$$=>{$r$$.phone=$r$$.recipientId||$r$$.dien_thoai||$r$$.phone||$r$$.phone_number});$payload_receivers$$.length==0&&$node$$?.data?.recipientId&&($payload_receivers$$=[{phone:$node$$?.data?.recipientId}]);for(let $receiver$$ of $payload_receivers$$){if($abortSignal$$.aborted)throw Logger.info(`[${$nodeInstanceId$$}] pushNotification node aborted before logging.`), new DOMException("Aborted by signal","AbortError");if(!$receiver$$?.messageText&&!$node$$?.data?.defaultMessage)throw"Kh\u00f4ng c\u00f3 n\u1ed9i dung tin nh\u1eafn";await sendMessageZalo($flowState_id_app$$,$receiver$$.phone,$template_id$$,$receiver$$)}return{result:`\u0110\u00e3 g\u1eedi tin nh\u1eafn t\u1edbi ${$payload_receivers$$.map($r$$=>$r$$.dien_thoai||$r$$.phone||$r$$.phone_number).join(",")}`}}module.exports=zaloSendMessageHandler;