Agent.secas.xml 1.73 KB
<?xml version="1.0" encoding="UTF-8"?>
<secas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-eca-3.xsd">
    <seca id="AgentTriggerOnCommunication" service="create#mantle.party.communication.CommunicationEvent" when="post-service">
        <actions>
            <script><![CDATA[
                ec.logger.info("SECA AgentTriggerOnCommunication fired for CommEvent ${communicationEventId} to Party ${toPartyId}")
                if (toPartyId == 'AGENT_CLAUDE_PARTY') {
                    def rootId = rootCommEventId ?: communicationEventId
                    if (!rootCommEventId) {
                        ec.service.sync().name("update#mantle.party.communication.CommunicationEvent")
                            .parameters([communicationEventId: communicationEventId, rootCommEventId: rootId])
                            .call()
                    }
                    
                    ec.logger.info("SECA AgentTriggerOnCommunication: Creating SmtyAgentTask SystemMessage for thread ${rootId}")
                    
                    // Trigger Agent Turn
                    ec.service.sync().name("create#moqui.service.message.SystemMessage").parameters([
                        systemMessageTypeId: 'SmtyAgentTask',
                        statusId: 'SmsgReceived',
                        requestedByPartyId: fromPartyId,
                        effectiveUserId: ec.user.userId, 
                        productStoreId: 'POPC_DEFAULT',
                        aiConfigId: 'DEFAULT',
                        rootCommEventId: rootId,
                        isOutgoing: 'N'
                    ]).call()
                }
            ]]></script>
        </actions>
    </seca>
</secas>