예제 #1
0
  @OnKeyword("tcfeed")
  public void feedbackform(TeamchatAPI api) {

    Form fo = api.objects().form();

    fo.addField(api.objects().input().name("TicketID").label("TicketID"));

    fo.addField(
        api.objects().select().name("Rating").label("Rating").addOption("good").addOption("bad"));

    fo.addField(api.objects().input().name("rcomment").label("Comment"));

    PrimaryChatlet prime = new PrimaryChatlet();

    api.perform(
        api.context()
            .currentRoom()
            .post(
                prime
                    .setQuestionHtml(
                        "<h3 style=\"color:black\";><b>Give Us Feedback</b></h3>"
                            + "<br />We value your feedback and product suggestions. While we don't respond to suggestions directly, we do review them. If you'd like to give general feedback about Teamchat support, give your feedback here.")
                    .setReplyScreen(fo)
                    .setReplyLabel("Enter")
                    .alias("getdatafeed")));
  }
예제 #2
0
  @OnAlias("sendreqadd")
  public void sendreqadd(TeamchatAPI api) throws IOException {
    String name = api.context().currentReply().getField("name");
    String host = api.context().currentReply().getField("host");
    String Protocol = api.context().currentReply().getField("Protocol");

    pingdomintegrator ob1 = new pingdomintegrator();

    String resp = ob1.addChecks(Username, Password, App_key, host, name, Protocol);

    if (resp.equals("Error")) {
      PrimaryChatlet prime = new PrimaryChatlet();
      api.perform(
          api.context()
              .currentRoom()
              .post(
                  prime.setQuestionHtml(
                      "<br /><b>Error :</b>"
                          + "<br /><b>Status Code: 403</b>"
                          + "<br /><b>StatusDesc: Forbidden</b>"
                          + "<br /><b>Something went wrong!</b>")));

    } else {

      api.perform(
          api.context()
              .currentRoom()
              .post(new PrimaryChatlet().setQuestionHtml("<br /><b>" + resp + "</b>")));
    }
  }
예제 #3
0
  @OnKeyword("tcsupport")
  public void support(TeamchatAPI api) {

    zd =
        new Zendesk.Builder("https://teamchat.zendesk.com") // Zendesk account id
            .setUsername("*****@*****.**") // email of zendesk account
            .setPassword("webaroo")
            .build(); // or setToken("0cf1d94606")

    // Setting up Trigger
    // trigger ();

    Form f = api.objects().form();
    f.addField(api.objects().input().label("Subject").name("subject"));
    f.addField(api.objects().input().label("Comment").name("comment"));
    f.addField(api.objects().input().label("Contact No.").name("contact"));

    PrimaryChatlet prime = new PrimaryChatlet();
    prime
        .setQuestionHtml(
            "<img src=\"http://p3.zdassets.com/hc/settings_assets/481529/200038422/Q2xRKEc55HY0Oxq8hxzRaw-teamchatsupportlogo.png\" height=\"90\" width=\"230\">"
                + "<br /><b>Enter your query below:</b>")
        .setReplyScreen(f)
        .setReplyLabel("Enter")
        .setDetailsLabel("Queries")
        .showDetails(true)
        .alias("query");

    api.perform(api.context().currentRoom().post(prime));
  }
예제 #4
0
  // communicating with pingdomintegrator class
  @OnAlias("sendreqdel")
  public void sendreqdel(TeamchatAPI api) throws IOException {

    int i;
    String chks[] = new String[count - 1];
    int s = 1;
    for (i = 0; i < count - 1; i++) {

      chks[i] = api.context().currentReply().getField("Checks" + String.valueOf(s));
      s++;
    }

    s = 1;
    url = "https://api.pingdom.com/api/2.0/checks";
    pingdomintegrator ob1 = new pingdomintegrator();

    String resp = ob1.getChecks(Username, Password, App_key, url);
    Gson gson = new Gson();
    Checks checks = gson.fromJson(resp, Checks.class);

    int k = 0;

    int del[] = new int[count - 1];

    for (Check check : checks.getChecks()) {
      if (check.getHostname().equals(chks[k])) {

        del[k] = check.getId();
      } else {

        del[k] = 1;
      }
      k++;
    }

    k = 1;

    String respdel = ob1.delChecks(Username, Password, App_key, del);

    if (respdel.equals("Error")) {
      PrimaryChatlet prime = new PrimaryChatlet();
      api.perform(
          api.context()
              .currentRoom()
              .post(
                  prime.setQuestionHtml(
                      "<br /><b>Error :</b>"
                          + "<br /><b>Status Code: 403</b>"
                          + "<br /><b>StatusDesc: Forbidden</b>"
                          + "<br /><b>Something went wrong!</b>")));

    } else {
      PrimaryChatlet prime = new PrimaryChatlet();
      api.perform(
          api.context().currentRoom().post(prime.setQuestionHtml("<br /><b>" + respdel + "</b>")));
    }
  }
예제 #5
0
  @OnKeyword("login")
  public void login(TeamchatAPI api) {

    Form f = api.objects().form();
    f.addField(api.objects().input().label("Username").name("Username"));
    f.addField(api.objects().input().label("Password").name("Password"));
    f.addField(api.objects().input().label("App_key").name("App_key"));

    PrimaryChatlet prime = new PrimaryChatlet();
    prime
        .setQuestionHtml("<h4><b>Enter your login credentials :</b></h4>")
        .setReplyScreen(f)
        .setReplyLabel("Enter")
        .alias("setdata");

    api.perform(api.context().currentRoom().post(prime));
  }
예제 #6
0
  @OnKeyword("addcheck")
  public void addcheck(TeamchatAPI api) throws IOException, SQLException {
    String rmid;
    rmid = api.context().currentRoom().getId();
    DBHandler ob4 = new DBHandler();
    boolean flag;
    flag = ob4.roomchk(rmid);

    if (flag == false) {
      PrimaryChatlet prime = new PrimaryChatlet();
      prime.setQuestionHtml(
          "<br /><b>First you have to sign in!!</b>"
              + "<br /><b>Note: </b><a1  style=\"color:#359FD8\";>For Signing in type \"login\" command</a1>");

      api.perform(api.context().currentRoom().post(prime));
    } else {
      DBHandler ob5 = new DBHandler();
      String[] usrpassapp = ob5.getusrpassapp(rmid);
      Username = usrpassapp[0];
      Password = usrpassapp[1];
      App_key = usrpassapp[2];
      url = "https://api.pingdom.com/api/2.0/checks";
      PrimaryChatlet prime = new PrimaryChatlet();
      Form f = api.objects().form();
      f.addField(api.objects().input().label("Check Name :").name("name"));
      f.addField(api.objects().input().label("Hostname :").name("host"));
      f.addField(
          api.objects()
              .select()
              .name("Protocol")
              .label("Select any protocol :")
              .addOption("http")
              .addOption("https"));

      prime
          .setQuestionHtml("<h5><b>Enter the Check details below:</b></h5>")
          .setReplyScreen(f)
          .setReplyLabel("Enter")
          .alias("sendreqadd");
      api.perform(api.context().currentRoom().post(prime));
    }
  }
  @OnKeyword("Createproject")
  public void createProject(TeamchatAPI api) throws IOException {

    Database_Handler db = new Database_Handler();
    pb = db.GetBasicStuff(api.context().currentSender().getEmail());
    GetAccount ga = new GetAccount();
    Field f = null;
    f = ga.getAccount(pb.getAccess_token(), api);
    PrimaryChatlet chtlet =
        new PrimaryChatlet()
            .setQuestion("Fill in details of the project")
            .setReplyScreen(
                api.objects()
                    .form()
                    .addField(api.objects().input().label("Project Name").name("project_name"))
                    .addField(f));

    chtlet.alias("createproject");

    api.performPostInCurrentRoom(chtlet);
  }
예제 #8
0
  @OnKeyword("logout")
  public void logout(TeamchatAPI api) throws SQLException {

    String rmid;
    rmid = api.context().currentRoom().getId();

    DBHandler chk = new DBHandler();
    boolean flag;
    flag = chk.roomchk(rmid);
    if (flag == true) {
      DBHandler datacng = new DBHandler();
      datacng.stmt.executeUpdate("DELETE FROM Bot.pingdom_auth" + " WHERE roomId='" + rmid + "'");
      datacng.conn.close();
      PrimaryChatlet prime = new PrimaryChatlet();
      prime.setQuestionHtml("<h5><b>You are successfully logged out!!</b></h5>");
      api.perform(api.context().currentRoom().post(prime));
    } else {
      PrimaryChatlet prime = new PrimaryChatlet();
      prime.setQuestionHtml("<h5><b>You are not logged in!!</b></h5>");
      api.perform(api.context().currentRoom().post(prime));
    }
  }
예제 #9
0
  @OnAlias("query")
  public void query(TeamchatAPI api) {
    zd =
        new Zendesk.Builder("https://teamchat.zendesk.com") // Zendesk account id
            .setUsername("*****@*****.**") // email of zendesk account
            .setPassword("webaroo")
            .build(); // or setToken("0cf1d94606")

    String sub = api.context().currentReply().getField("subject");
    String com = api.context().currentReply().getField("comment");
    String con = api.context().currentReply().getField("contact");

    // Setting comment
    Comment c = new Comment();
    c.setBody(com);

    // Creating a new ticket, administrator privilege is required
    Ticket ticket = new Ticket();
    ticket.setSubject(sub);
    ticket.setComment(c);

    ticket = zd.createTicket(ticket);
    ticketId = String.valueOf(ticket.getId());
    requesterId = String.valueOf(ticket.getRequesterId());
    String stat = "open";
    String rat = "";
    String Rc = "";

    Form f = api.objects().form();
    f.addField(api.objects().input().label("Comment").name("upCom"));

    PrimaryChatlet prime = new PrimaryChatlet();
    prime
        .setQuestionHtml(
            "<h4><b>Ticket Details:</b></h4>"
                + "<ul type=\"square\"; style=\"color:#359FD8\";><li><a1 style=\"color:black\";><b>Ticket ID- </b></a1><a2 style=\"color:#359FD8\";>"
                + ticketId
                + "</a2></li><li><a3 style=\"color:black\";><b>Requester ID- </b></a3><a4 style=\"color:#359FD8\";>"
                + requesterId
                + "</a4></li><li><a5 style=\"color:black\";><b>Subject - </b></a5><a6 style=\"color:#359FD8\";>"
                + sub
                + "</a6></li><li><a7 style=\"color:black\";><b>Comment - </b></a7><a8 style=\"color:#359FD8\";>"
                + com
                + "</a8></li></ul>")
        .setReplyScreen(f)
        .setReplyLabel("Update")
        .setDetailsLabel("Update")
        .showDetails(true)
        .alias("update");

    api.perform(api.context().currentRoom().post(prime));

    roomId = api.context().currentRoom().getId();
    formId = prime.getFormId();
    comment = com;
    contact = con;
    status = stat;
    rating = rat;
    Rcomment = Rc;

    // System.out.println("TICKET ID"+ticketId);
    //	System.out.println("REQUESTER ID"+requesterId);
    //	System.out.println("FORM ID"+formId);
    //	System.out.println("ROOM ID"+roomId);
    //	System.out.println(status);
    ticketData.setData(
        roomId, formId, ticketId, requesterId, comment, contact, status, rating, Rcomment);

    // Saving ticketid with formid for further replies
    // api.data().addField (formId, "RoomID", roomId);
    // api.data().addField (formId, "FormID", formId);
    // api.data().addField (formId, "TicketID", ticketId);
    // api.data().addField (formId, "RequesterID", requesterId);
  }
예제 #10
0
  @OnAlias("sendreqcheck")
  public void sendreqcheck(TeamchatAPI api) throws IOException {

    int i;
    String chks[] = new String[count - 1];
    int s = 1;
    for (i = 0; i < count - 1; i++) {

      chks[i] = api.context().currentReply().getField("Checks" + String.valueOf(s));
      s++;
    }
    count = 1;
    s = 1;
    url = "https://api.pingdom.com/api/2.0/checks";
    pingdomintegrator ob1 = new pingdomintegrator();
    String resp = ob1.getChecks(Username, Password, App_key, url);

    Gson gson = new Gson();
    Checks checks = gson.fromJson(resp, Checks.class);

    int k = 0;
    String color;
    color = "#359FD8";
    // color="#CF0909";--red
    // color="#24970D";---green
    int len = chks.length;
    for (Check check : checks.getChecks()) {
      for (k = 0; k < len; k++) {
        if (check.getHostname().equals(chks[k])) {
          if (check.getStatus().equals("up")) {

            color = "#24970D";

          } else if (check.getStatus().equalsIgnoreCase("down")) {
            color = "#CF0909";
          }
          PrimaryChatlet prime1 = new PrimaryChatlet();
          prime1.setQuestionHtml(
              "<h4><b>Host Details "
                  + String.valueOf(s)
                  + ":</b></h4>"
                  + "<ul type=\"square\"; style=\"color:#359FD8\";><li><a1 style=\"color:black\";><b>Name- </b></a1><a2 style=\"color:#359FD8\";>"
                  + check.getName()
                  + "</a2></li><li><a3 style=\"color:black\";><b>Hostname- </b></a3><a4 style=\"color:#359FD8\";>"
                  + check.getHostname()
                  + "</a4></li><li><a5 style=\"color:black\";><b>Status - </b></a5><a6 style=\"color:"
                  + color
                  + "\";>"
                  + check.getStatus()
                  + "</a6></li><li><a7 style=\"color:black\";><b>Last Response Time - </b></a7><a8 style=\"color:#359FD8\";>"
                  + check.getLastresponsetime()
                  + " ms"
                  + "</a8></li><li><a9 style=\"color:black\";><b>Type - </b></a9><a10 style=\"color:#359FD8\";>"
                  + check.getType()
                  + "</a10></li></ul>");
          api.perform(api.context().currentRoom().post(prime1));

          s++;
        }
      }
    }

    s = 1;
  }
예제 #11
0
  @OnKeyword("deletecheck")
  public void deletecheck(TeamchatAPI api) throws IOException, SQLException {
    String rmid;
    count = 1;
    rmid = api.context().currentRoom().getId();
    DBHandler ob4 = new DBHandler();
    boolean flag;
    flag = ob4.roomchk(rmid);

    if (flag == false) {
      PrimaryChatlet prime = new PrimaryChatlet();
      prime.setQuestionHtml(
          "<br /><b>First you have to sign in!!</b>"
              + "<br /><b>Note: </b><a1  style=\"color:#359FD8\";>For Signing in type \"login\" command</a1>");

      api.perform(api.context().currentRoom().post(prime));
    } else {
      DBHandler ob5 = new DBHandler();
      String[] usrpassapp = ob5.getusrpassapp(rmid);
      Username = usrpassapp[0];
      Password = usrpassapp[1];
      App_key = usrpassapp[2];
      url = "https://api.pingdom.com/api/2.0/checks";
      pingdomintegrator ob1 = new pingdomintegrator();
      String resp = ob1.getChecks(Username, Password, App_key, url);

      if (resp.equals("Error")) {
        PrimaryChatlet prime = new PrimaryChatlet();
        api.perform(
            api.context()
                .currentRoom()
                .post(
                    prime.setQuestionHtml(
                        "<br /><b>Error :</b>"
                            + "<br /><b>Status Code: 403</b>"
                            + "<br /><b>StatusDesc: Forbidden</b>"
                            + "<br /><b>Something went wrong!</b>")));

      } else {

        Gson gson = new Gson();
        Checks checks = gson.fromJson(resp, Checks.class);
        Form fo = api.objects().form();

        for (Check check : checks.getChecks()) {

          fo.addField(
              api.objects()
                  .select()
                  .name("Checks" + String.valueOf(count))
                  .label("Select check " + String.valueOf(count) + ":")
                  .addOption(check.getHostname())
                  .addOption("none"));

          count++;
        }

        api.perform(
            api.context()
                .currentRoom()
                .post(
                    new PrimaryChatlet()
                        .setQuestionHtml("<br /><b>Select Checks from below :</b>")
                        .setReplyScreen(fo)
                        .setReplyLabel("Enter")
                        .alias("sendreqdel")));
      }
    }
  }
예제 #12
0
  @OnKeyword("ping")
  public void ping(TeamchatAPI api) throws IOException, SQLException {
    String rmid;
    count = 1;
    // getting roomid
    rmid = api.context().currentRoom().getId();
    DBHandler ob4 = new DBHandler();
    boolean flag;
    flag = ob4.roomchk(rmid);
    // checking if roomid is available in the database.If it is available then user will be logged
    // in automatically n flag will become true else false
    if (flag == false) {
      PrimaryChatlet prime = new PrimaryChatlet();
      prime.setQuestionHtml(
          "<br /><b>First you have to sign in!!</b>"
              + "<br /><b>Note: </b><a1  style=\"color:#359FD8\";>For Signing in type \"login\" command</a1>");

      api.perform(api.context().currentRoom().post(prime));
    } else {
      DBHandler ob5 = new DBHandler();
      String[] usrpassapp = ob5.getusrpassapp(rmid);
      Username = usrpassapp[0];
      Password = usrpassapp[1];
      App_key = usrpassapp[2];
      url = "https://api.pingdom.com/api/2.0/checks";
      pingdomintegrator ob1 = new pingdomintegrator();
      String resp = ob1.getChecks(Username, Password, App_key, url);

      // error if there is some issue in the authentication.

      if (resp.equals("Error")) {
        PrimaryChatlet prime = new PrimaryChatlet();
        api.perform(
            api.context()
                .currentRoom()
                .post(
                    prime.setQuestionHtml(
                        "<br /><b>Error :</b>"
                            + "<br /><b>Status Code: 403</b>"
                            + "<br /><b>StatusDesc: Forbidden</b>"
                            + "<br /><b>Something went wrong!</b>")));

      } else {

        // parsing a json like this

        // {
        // "checks": [
        // {
        // "id": 1650784,
        // "created": 1435769579,
        // "name": "google",
        // "hostname": "www.google.com",
        // "use_legacy_notifications": true,
        // "resolution": 1,
        // "type": "http",
        // "lasttesttime": 1435806884,
        // "lastresponsetime": 167,
        // "status": "up",
        // "probe_filters": []
        // },
        // {
        // "id": 1650785,
        // "created": 1435769756,
        // "name": "Teamchat",
        // "hostname": "www.teamchat.com",
        // "use_legacy_notifications": true,
        // "resolution": 1,
        // "type": "http",
        // "lasttesttime": 1435806881,
        // "lastresponsetime": 725,
        // "status": "up",
        // "probe_filters": []
        // },
        // {
        // "id": 1650787,
        // "created": 1435769804,
        // "name": "Interns Teamchat",
        // "hostname": "interns.teamchat.com",
        // "use_legacy_notifications": true,
        // "resolution": 1,
        // "type": "http",
        // "lasterrortime": 1435806882,
        // "lasttesttime": 1435806882,
        // "lastresponsetime": 0,
        // "status": "down",
        // "probe_filters": []
        // }
        // ],
        // "counts": {
        // "total": 3,
        // "limited": 3,
        // "filtered": 3
        // }
        // }

        Gson gson = new Gson();
        Checks checks = gson.fromJson(resp, Checks.class);
        Form fo = api.objects().form();

        for (Check check : checks.getChecks()) {

          fo.addField(
              api.objects()
                  .select()
                  .name("Checks" + String.valueOf(count))
                  .label("Select check " + String.valueOf(count) + ":")
                  .addOption(check.getHostname())
                  .addOption("none"));

          count++;
        }

        api.perform(
            api.context()
                .currentRoom()
                .post(
                    new PrimaryChatlet()
                        .setQuestionHtml("<br /><b>Select Checks from below :</b>")
                        .setReplyScreen(fo)
                        .setReplyLabel("Enter")
                        .alias("sendreqcheck")));
      }
    }
  }