SDK: add ChatHandler options

- fix classes names to capitalize
- add set -e to bash scripts
- code cleanup

Change-Id: Icc5c096afac62b7fe88f15496b15c4bfb45a9b0d
GitLab: #5
diff --git a/AutoAnswer/BotPeerChatSubscriber.cpp b/AutoAnswer/BotPeerChatSubscriber.cpp
new file mode 100644
index 0000000..0d30eb6
--- /dev/null
+++ b/AutoAnswer/BotPeerChatSubscriber.cpp
@@ -0,0 +1,93 @@
+/**
+ *  Copyright (C) 2020 Savoir-faire Linux Inc.
+ *
+ *  Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#include "BotPeerChatSubscriber.h"
+#include "pluglog.h"
+
+const std::string TAG = "bot";
+
+namespace jami {
+
+BotPeerChatSubscriber::BotPeerChatSubscriber(const JAMI_PluginAPI* api, std::string& textAnswer)
+    : api_ {api}
+    , textAnswer_ {textAnswer}
+{}
+
+BotPeerChatSubscriber::~BotPeerChatSubscriber()
+{
+    std::ostringstream oss;
+    oss << "~botChatProcessor" << std::endl;
+    Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
+}
+
+void
+BotPeerChatSubscriber::update(Observable<pluginMessagePtr>*, const pluginMessagePtr& message)
+{
+    if (isAttached) {
+        if (message->direction) {
+            std::map<std::string, std::string> sendMsg;
+            for (auto& pair : message->data) {
+                if (pair.first == "text/plain" && pair.second == "hi") {
+                    std::ostringstream sendMsgStream;
+                    sendMsgStream << "HelloWorld from bot plugin";
+                    sendMsg[pair.first] = sendMsgStream.str();
+                }
+            }
+            if (!sendMsg.empty()) {
+                sendText(message->accountId, message->peerId, sendMsg);
+            }
+        }
+    }
+}
+
+void
+BotPeerChatSubscriber::attached(Observable<pluginMessagePtr>* observable)
+{
+    if (observables_.find(observable) == observables_.end()) {
+        std::ostringstream oss;
+        oss << "::Attached ! " << std::endl;
+        Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
+        observables_.insert(observable);
+        isAttached = true;
+    }
+}
+
+void
+BotPeerChatSubscriber::detached(Observable<pluginMessagePtr>* observable)
+{
+    if (observables_.find(observable) != observables_.end()) {
+        observables_.erase(observable);
+        std::ostringstream oss;
+        oss << "::Detached()" << std::endl;
+        Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
+        if (observables_.empty())
+            isAttached = false;
+    }
+}
+
+void
+BotPeerChatSubscriber::sendText(std::string& accountId,
+                                std::string& peerId,
+                                std::map<std::string, std::string>& sendMsg)
+{
+    pluginMessagePtr botAnswer = std::make_shared<JamiMessage>(accountId, peerId, false, sendMsg, true);
+    api_->invokeService(api_, "sendTextMessage", botAnswer.get());
+}
+} // namespace jami