|
6 | 6 | import com.t4a.api.JavaMethodAction;
|
7 | 7 |
|
8 | 8 | import com.t4a.detect.ActionCallback;
|
| 9 | +import com.t4a.detect.ActionState; |
9 | 10 | import com.t4a.processor.AIProcessor;
|
10 | 11 | import lombok.extern.java.Log;
|
11 | 12 | import org.springframework.stereotype.Service;
|
|
16 | 17 | public class RaiseCustomerTicket {
|
17 | 18 | /**
|
18 | 19 | * Each action has access to AIProcessor and ActionCallback which are autowired by tools4ai
|
| 20 | + * Use ThreadLocal to store the ActionCallback for the current thread if you are concerned |
| 21 | + * about concurrency issues. |
19 | 22 | */
|
20 |
| - private ActionCallback callback; |
| 23 | + private static final ThreadLocal<ActionCallback> callbackThreadLocal = new ThreadLocal<>(); |
21 | 24 |
|
22 | 25 | /**
|
23 | 26 | * Each action has access to AIProcessor and ActionCallback which are autowired by tools4ai
|
24 | 27 | */
|
25 | 28 | private AIProcessor processor;
|
26 | 29 | @Action(description = "Raise a ticket for customer")
|
27 |
| - public String raiseTicket(String customerName) { |
28 |
| - |
| 30 | + public String raiseTicket(String customerName, String reason) { |
| 31 | + if(callbackThreadLocal.get() != null) { |
| 32 | + ActionCallback callback = callbackThreadLocal.get(); |
| 33 | + log.info("callback is set "+callback); |
| 34 | + // you can call the callback to get the AIProcessor |
| 35 | + if(callback!=null) { |
| 36 | + //the spelling mistake in the message is intentional to test the callback and the ai |
| 37 | + callback.sendtStatus("raiseed ticket for will be resoved soon , t"+customerName+ " reason "+reason, ActionState.COMPLETED); |
| 38 | + } |
| 39 | + } else { |
| 40 | + log.warning("callback is not set"); |
| 41 | + } |
29 | 42 | return "ticket 111 raised for "+customerName;
|
30 | 43 | }
|
31 | 44 | }
|
0 commit comments