Sametime meets Watson

  • 06 Dec, 2016

Bots is a high topic these days and i revisited this kind of application last week.

I created a Translation Bot based on this article from IBM.

This Sametime Bot get the text, send to IBM Watson Translation Service and return the translated text to the user.

public void textReceived(ImEvent e) {                    String q = e.getText();                //here we connect to watson and get the translation         LanguageTranslation service = new LanguageTranslation();         service.setUsernameAndPassword("<username>","<password>");         service.setEndPoint("https://gateway.watsonplatform.net/language-translator/api");         List<IdentifiedLanguage> identifiedLanguages = service.identify(e.getText()).execute();         String lang = identifiedLanguages.get(0).getLanguage();         String idiomaPt = "pt";         String idiomaEn = "en";         String idiomait = "it";         if (lang.equals(idiomaPt) | lang.equals(idiomait)) {             TranslationResult result = service.translate(e.getText(),Language.PORTUGUESE,Language.ENGLISH).execute();              e.getIm().sendText(true, result.getFirstTranslation()+".");                      } else if (lang.equals(idiomaEn)) {             TranslationResult result = service.translate(e.getText(),Language.ENGLISH,Language.PORTUGUESE).execute();              e.getIm().sendText(true, result.getFirstTranslation()+".");                      } else {             e.getIm().sendText(true,"Não consigo traduzir.");         }              System.err.println("Message received from " + e.getIm().getPartner().getName());     }

To run the bot i export the project as an executable JAR and run it on my linux server using the script bellow:

#!/bin/sh SERVICE_NAME=STBot PATH_TO_JAR=/etc/init.d/STBotV02.jar PID_PATH_NAME=/etc/init.d/Stbot-pid case $1 in     start)         echo "Starting $SERVICE_NAME ..."         if [ ! -f $PID_PATH_NAME ]; then             nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &                         echo $! > $PID_PATH_NAME             echo "$SERVICE_NAME started ..."         else             echo "$SERVICE_NAME is already running ..."         fi     ;;     stop)         if [ -f $PID_PATH_NAME ]; then             PID=$(cat $PID_PATH_NAME);             echo "$SERVICE_NAME stoping ..."             kill $PID;             echo "$SERVICE_NAME stopped ..."             rm $PID_PATH_NAME         else             echo "$SERVICE_NAME is not running ..."         fi     ;;     restart)         if [ -f $PID_PATH_NAME ]; then             PID=$(cat $PID_PATH_NAME);             echo "$SERVICE_NAME stopping ...";             kill $PID;             echo "$SERVICE_NAME stopped ...";             rm $PID_PATH_NAME             echo "$SERVICE_NAME starting ..."             nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &                         echo $! > $PID_PATH_NAME             echo "$SERVICE_NAME started ..."         else             echo "$SERVICE_NAME is not running ..."         fi     ;; esac

Related Posts

Sametime and IBM Connections integration when you use self certification

  • 20 Oct, 2015

I setup the integration between Sametime Proxy 9.0 and IBM Connections a long time ago. When i access the Connections homepage the sametime widget does not work. After some research i found a solutio

Sametime and IBM Connections integration when you use self certificationRead More

Upgrade the embedded sametime client on Notes 9

  • 24 Sep, 2013

IBM Sametime 9 was launched a few weeks ago.  When i saw this video(http://ibmtvdemo.edgesuite.net/software/lotus/uxid/sametime/ST9wn.mp4) i  do the upgrade of my embedded Sametime client on Notes 9

Upgrade the embedded sametime client on Notes 9Read More

Removal of ST Links Support

  • 07 May, 2013

Support for Sametime integration with ST Links has been dropped in iNotes 9.0. For this release, only Sametime Web Client integration via a Sametime Proxy Server will be supported. This will be the de

Removal of ST Links SupportRead More