finos / symphony-wdk

Symphony Workflow Developer Kit (WDK), a bot capable of running workflows
Apache License 2.0
3 stars 10 forks source link

Cannot use text() function in message templates #95

Closed ystxn closed 2 years ago

ystxn commented 2 years ago

Bug Report

The text() function does not work when used within a send-message template file https://github.com/finos/symphony-wdk/blob/master/docs/reference.md#string-textstring-presentationml

Steps to Reproduce:

hello.swadl.yaml

id: hello
activities:
  - send-message:
      id: init
      on:
        message-received:
          content: hello
      content:
          template: hello.ftl

hello.ftl

I heard this: ${text(event.source.message.message)}

Expected Result:

Bot responds with I heard this: hello to hello command

Actual Result:

ERROR 1295 --- [aTaskExecutor-1] c.s.b.w.engine.camunda.CamundaExecutor   : Activity init:51954532-a5ea-11ec-8047-acde48001122 from workflow 518bcf41-a5ea-11ec-8047-acde48001122 failed

com.symphony.bdk.template.api.TemplateException: Could not generate string from template
    at com.symphony.bdk.template.freemarker.FreeMarkerTemplate.process(FreeMarkerTemplate.java:40) ~[symphony-bdk-template-freemarker-2.5.0.jar!/:2.5.0]
    at com.symphony.bdk.workflow.engine.executor.message.SendMessageExecutor.extractContent(SendMessageExecutor.java:121) ~[classes!/:na]
    at com.symphony.bdk.workflow.engine.executor.message.SendMessageExecutor.buildMessage(SendMessageExecutor.java:100) ~[classes!/:na]
    at com.symphony.bdk.workflow.engine.executor.message.SendMessageExecutor.execute(SendMessageExecutor.java:43) ~[classes!/:na]
    at com.symphony.bdk.workflow.engine.camunda.CamundaExecutor.execute(CamundaExecutor.java:114) ~[classes!/:na]
    at org.camunda.bpm.engine.impl.bpmn.delegate.JavaDelegateInvocation.invoke(JavaDelegateInvocation.java:40) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:58) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocationInContext(DefaultDelegateInterceptor.java:92) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:63) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskJavaDelegateActivityBehavior.execute(ServiceTaskJavaDelegateActivityBehavior.java:55) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.bpmn.behavior.ServiceTaskJavaDelegateActivityBehavior.performExecution(ServiceTaskJavaDelegateActivityBehavior.java:44) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior.execute(TaskActivityBehavior.java:69) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.bpmn.behavior.ClassDelegateActivityBehavior$1.call(ClassDelegateActivityBehavior.java:68) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.bpmn.behavior.ClassDelegateActivityBehavior$1.call(ClassDelegateActivityBehavior.java:65) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.executeWithErrorPropagation(AbstractBpmnActivityBehavior.java:90) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.bpmn.behavior.ClassDelegateActivityBehavior.execute(ClassDelegateActivityBehavior.java:65) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute$2.callback(PvmAtomicOperationActivityExecute.java:61) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute$2.callback(PvmAtomicOperationActivityExecute.java:50) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.continueIfExecutionDoesNotAffectNextOperation(PvmExecutionImpl.java:2039) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:42) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationActivityExecute.execute(PvmAtomicOperationActivityExecute.java:31) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.AtomicOperationInvocation.execute(AtomicOperationInvocation.java:99) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.invokeNext(CommandInvocationContext.java:131) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performNext(CommandInvocationContext.java:111) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:86) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:634) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:608) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl$6.callback(PvmExecutionImpl.java:1978) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl$6.callback(PvmExecutionImpl.java:1975) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.continueExecutionIfNotCanceled(PvmExecutionImpl.java:2045) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.dispatchDelayedEventsAndPerformOperation(PvmExecutionImpl.java:1994) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl.dispatchDelayedEventsAndPerformOperation(PvmExecutionImpl.java:1975) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(PvmAtomicOperationTransitionNotifyListenerStart.java:60) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(PvmAtomicOperationTransitionNotifyListenerStart.java:30) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.core.operation.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:66) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.AtomicOperationInvocation.execute(AtomicOperationInvocation.java:99) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.invokeNext(CommandInvocationContext.java:131) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performNext(CommandInvocationContext.java:111) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:86) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:76) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:643) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:618) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.core.operation.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:62) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.AtomicOperationInvocation.execute(AtomicOperationInvocation.java:99) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.invokeNext(CommandInvocationContext.java:131) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performNext(CommandInvocationContext.java:111) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:86) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:76) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:643) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:618) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.core.operation.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:62) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.AtomicOperationInvocation.execute(AtomicOperationInvocation.java:99) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.invokeNext(CommandInvocationContext.java:131) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performNext(CommandInvocationContext.java:111) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:86) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:76) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:643) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:618) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.core.operation.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:62) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.AtomicOperationInvocation.execute(AtomicOperationInvocation.java:99) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.invokeNext(CommandInvocationContext.java:131) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performNext(CommandInvocationContext.java:111) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:86) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:634) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:608) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationTransitionCreateScope.scopeCreated(PvmAtomicOperationTransitionCreateScope.java:38) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationCreateScope.execute(PvmAtomicOperationCreateScope.java:54) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.pvm.runtime.operation.PvmAtomicOperationCreateScope.execute(PvmAtomicOperationCreateScope.java:28) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.AtomicOperationInvocation.execute(AtomicOperationInvocation.java:99) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.invokeNext(CommandInvocationContext.java:131) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performNext(CommandInvocationContext.java:118) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:86) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandInvocationContext.performOperation(CommandInvocationContext.java:76) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.jobexecutor.AsyncContinuationJobHandler.execute(AsyncContinuationJobHandler.java:81) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.jobexecutor.AsyncContinuationJobHandler.execute(AsyncContinuationJobHandler.java:40) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:134) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:110) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:43) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:28) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:110) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:72) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.15.jar!/:5.3.15]
    at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:70) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.CommandCounterInterceptor.execute(CommandCounterInterceptor.java:35) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:57) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:110) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:71) ~[camunda-engine-7.16.0.jar!/:7.16.0]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> text  [in template "hello.ftl" at line 1, column 17]

----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----

----
FTL stack trace ("~" means nesting-related):
    - Failed at: ${text(event.source.message.message)}  [in template "hello.ftl" at line 1, column 15]
----
    at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.UnexpectedTypeException.newDescriptionBuilder(UnexpectedTypeException.java:85) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:63) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.NonMethodException.<init>(NonMethodException.java:74) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.MethodCall._eval(MethodCall.java:67) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.Expression.eval(Expression.java:101) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.DollarVariable.accept(DollarVariable.java:63) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.Environment.visit(Environment.java:347) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.Environment.visit(Environment.java:353) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.core.Environment.process(Environment.java:326) ~[freemarker-2.3.31.jar!/:2.3.31]
    at freemarker.template.Template.process(Template.java:383) ~[freemarker-2.3.31.jar!/:2.3.31]
    at com.symphony.bdk.template.freemarker.FreeMarkerTemplate.process(FreeMarkerTemplate.java:37) ~[symphony-bdk-template-freemarker-2.5.0.jar!/:2.5.0]
    ... 91 common frames omitted

Environment:

WDK 1.0.0-RC2

symphony-youri commented 2 years ago

It is probably here: https://github.com/finos/symphony-wdk/blob/4f700493691c88e2be6cdaa22acf79b93d2c447a/workflow-bot-app/src/main/java/com/symphony/bdk/workflow/engine/executor/message/SendMessageExecutor.java#L117 that we could try to bind the utility functions to the template engine

symphony-elias commented 2 years ago

We could leverage this: https://freemarker.apache.org/docs/pgui_datamodel_method.html