@OnKeyword("Notification") public void Notification(TeamchatAPI api) { String URL = "https://www.pivotaltracker.com/services/v5/my/notifications"; String URL_parameter = "envelope=true"; Database_Handler db = new Database_Handler(); pb = db.GetBasicStuff(api.context().currentSender().getEmail()); SendGet sg = new SendGet(); // list of messages String responseHTML = ""; @SuppressWarnings("unused") Field f = null; try { String jsonData = sg.sendGet(URL, USER_AGENT, URL_parameter, pb.getAccess_token()); @SuppressWarnings("unused") Gson gson = new Gson(); JSONArray jsonArray = new JSONObject(jsonData).getJSONArray("data"); for (int i = 0; i < jsonArray.length(); i++) { responseHTML += jsonArray.getJSONObject(i).get("message").toString() + "<br />"; } System.out.println("Notifications are:" + responseHTML); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } api.perform( api.context().currentRoom().post(new PrimaryChatlet().setQuestionHtml(responseHTML))); }
@OnKeyword("Deletestory") public void deleteStory(TeamchatAPI api) { Database_Handler db = new Database_Handler(); pb = db.GetBasicStuff(api.context().currentSender().getEmail()); GetProjects gp = new GetProjects(); Field f = null; f = gp.getProject(pb.getAccess_token(), api); api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestion("Select project in which the story exists") .setReplyScreen(api.objects().form().addField(f)) .alias("selectedproject"))); }
@OnKeyword("Deleteproject") public void deleteProject(TeamchatAPI api) throws ClientProtocolException, IOException { Database_Handler db = new Database_Handler(); pb = db.GetBasicStuff(api.context().currentSender().getEmail()); GetProjects gp = new GetProjects(); Field f = null; f = gp.getProject(pb.getAccess_token(), api); api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestion("Select project to be deleted") .setReplyScreen(api.objects().form().addField(f)) .alias("deleteproject"))); }
@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); }
@OnKeyword("Createstory") public void createStory(TeamchatAPI api) { Database_Handler db = new Database_Handler(); pb = db.GetBasicStuff(api.context().currentSender().getEmail()); GetProjects gp = new GetProjects(); Field f_pid = null; f_pid = gp.getProject(pb.getAccess_token(), api); api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestion("Fill in details of the story") .setReplyScreen( api.objects() .form() .addField(api.objects().input().label("Story Name:").name("story_name")) .addField(api.objects().input().label("Description").name("notes")) .addField(f_pid)) .alias("createstory"))); }
@OnKeyword("help") public void Pivotal(TeamchatAPI api) throws IOException { api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestionHtml( "<br/>Hi! This is Pivotal Tracker Bot. I am going to guide you how to use me to do thinks in Tracker.<br/>Type the following commands to:<br/>1)Createproject: To create project<br/>2)Deleteproject: To delete project<br/>3)Createstory: To add story<br/>4)Deletestory: To delete story<br/>5)Notification: To get notifications<br/>6)Logout: To log out<br/>BUT FIRST YOU HAVE TO LOGIN!"))); email = api.context().currentSender().getEmail(); if (db.isAuthorized(email)) { // get the basic info api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestionHtml( "Hi, you may proceed to use your <u>Pivotal account</u>. "))); // welcome message and continue } else { // display the button so the user can begin authentication api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestionHtml( "Follow the instructions given below.We need you to get your access token one time.<br/>Open your Pivotal account.<br/>Click on your username in the top right.<br/>Click on Profile.<br/> Scroll down to API TOKEN. <br/>Copy the api token from the api token field and paste below.<html><body><a target='_blank' href='https://www.pivotaltracker.com/profile'>To Get to your profile click here</a><br/>"))); Form f = api.objects().form(); f.addField(api.objects().input().name("token").label("Paste Token here")); api.perform( api.context() .currentRoom() .post( new PrimaryChatlet() .setQuestionHtml("Paste your token") .setReplyScreen(f) .setReplyLabel("Enter") .alias("got_token"))); } }
@OnAlias("got_token") public static void got_token(TeamchatAPI api) { token = api.context().currentReply().getField("token"); db.StorageHandler(email, token); }
@OnKeyword("Logout") public void Logout(TeamchatAPI api) { Database_Handler db = new Database_Handler(); db.DeleteData(api.context().currentSender().getEmail()); api.perform(api.context().currentRoom().post(new TextChatlet("You have been logged out."))); }