[ 
https://issues.apache.org/jira/browse/CAMEL-12955?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16708846#comment-16708846
 ] 

ASF GitHub Bot commented on CAMEL-12955:
----------------------------------------

dmvolod commented on a change in pull request #2653: CAMEL-12955 Create a 
Camel-ChatScript component changes
URL: https://github.com/apache/camel/pull/2653#discussion_r238696763
 
 

 ##########
 File path: 
components/camel-chatscript/src/main/java/org/apache/camel/component/chatscript/ChatScriptProducer.java
 ##########
 @@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.chatscript;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+
+/**
+ * The ChatScript producer.
+ */
+public class ChatScriptProducer extends DefaultProducer {
+    private ChatScriptEndpoint endpoint;
+    private ObjectMapper mapper = new ObjectMapper();
+    public ChatScriptProducer(ChatScriptEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+
+        if (endpoint.isResetChat()) {
+            this.endpoint.getBot().reset();
+        }
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        Object body = exchange.getIn().getBody();
+        ChatScriptMessage inputMessage = new ChatScriptMessage();
+        /* use can pass message object as json or the object it self */
+        if (!(body instanceof ChatScriptMessage)) {
+            inputMessage = buildMessage(body);
+        } else {
+            inputMessage = (ChatScriptMessage) body;
+        }
+        String response = this.endpoint.getBot().sendChat(inputMessage);
+        inputMessage.setReply(response);
+        exchange.getOut().setBody(inputMessage);
+    }
+
+    private ChatScriptMessage buildMessage(Object body) {
+
+        if (body instanceof String) {
+            return createMessage(body);
+        }
+        return null;
+    }
+
+    private ChatScriptMessage createMessage(Object body) {
+        ChatScriptMessage ret = null;
+        try {
+            ret = mapper.readValue(String.valueOf(body), 
ChatScriptMessage.class);
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
 
 Review comment:
   It's a worth practice to skip exception there 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Create a Camel-ChatScript component
> -----------------------------------
>
>                 Key: CAMEL-12955
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12955
>             Project: Camel
>          Issue Type: New Feature
>            Reporter: Varun Krish
>            Assignee: Andrea Cosentino
>            Priority: Major
>             Fix For: Future
>
>
> Create new component to interact with ChatScript BOTs.
> Chat Script: [https://github.com/bwilcox-1234/ChatScript]
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to