Skip to content

Commit

Permalink
TextArea replaces input.
Browse files Browse the repository at this point in the history
Remove trailing return character
Introduces factory for Handlers
Introduces PostMessageOnEnterKey
  • Loading branch information
Vinod committed Aug 3, 2019
1 parent b446ba9 commit e0eff4c
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 38 deletions.
2 changes: 0 additions & 2 deletions Alice.Common/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alice.Common
{
Expand Down
16 changes: 16 additions & 0 deletions Alice.Framework/Alice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ public IAliceResponse Ask(UserRequest request)

public IAliceResponse Ask(string userMessage)
{
userMessage = CleanupRequestMessage(userMessage);

IAliceResponse response;
response = ProcessMessage(userMessage);
return response;
}

private IAliceResponse ProcessMessage(string userMessage)
{
userMessage = CleanupRequestMessage(userMessage);

CommandFinder finder = new CommandFinder();
Tuple<Command, IAliceRequestHandler> tuple;
tuple = finder.FindOrDefault(userMessage);
Expand All @@ -32,5 +36,17 @@ private IAliceResponse ProcessMessage(string userMessage)

return response;
}

private string CleanupRequestMessage(string userMessage)
{
string result = userMessage;
if (result.StartsWith("\n"))
result = result.Substring(1, result.Length - 1);

if (result.EndsWith("\n"))
result = result.Substring(0, result.Length - 1);

return result;
}
}
}
8 changes: 7 additions & 1 deletion Alice.Framework/Future implementation reference.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
Irritated: When someone repeats requests
Bored: When no one talk for an hour at least
//TODO ask and record questionnaire
//TODO Suggested actions for response
Icon, text, command
repeat booking for next day, cancel booking

//Done Implement add bookie name
//Done Implement add booking reason
Expand Down Expand Up @@ -109,18 +112,21 @@ will it rain in the evening?
will it rain in evening?

/********************************/
Task management
Idea: Task management
/********************************/
Start task X/working on X/started working on X
(Alice can show a time counter in big letters. also time consumed till last session)
Pause/paused - pauses current task
paused waiting for vinod to complete his task
Completed - completes current task
Completed X - completes X task, reports PM (A completed task X in 50 minutes (from a,b))
- Did you self review your task?
- Yes (send report now)
- I informed a,b,c
(When completed before time alice can congratulate)

Show my tasks pending
(when no tasks - alice can ping managers that someone is out of task)
Show my tasks completed this week,last week, this month,last month
Report my tasks - reports tasks to manager

Expand Down
4 changes: 0 additions & 4 deletions Alice.Framework/RequestBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Alice.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Alice.Framework
Expand Down
40 changes: 40 additions & 0 deletions RoomBookingLib/AliceRepeatBookingRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Alice.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RoomBookingExtension
{
class AliceRepeatBookingRequestHandler : IInternalRequestHandler
{
BookingRepository _bookingRepository;

public AliceRepeatBookingRequestHandler(BookingRepository bookingRepository)
{
_bookingRepository = bookingRepository;
}

public IAliceResponse Handle(IAliceRequest aliceRequest)
{
BookingRequestsBuilder requestsBuilder = new BookingRequestsBuilder(aliceRequest.Parameters, aliceRequest.UserProfile);
BookingRequest bookingRequest;
bookingRequest = requestsBuilder.Build();

Booking booking;
IAliceResponse response = new AliceResponse();
try
{
booking = _bookingRepository.Book(bookingRequest);
response.Message = string.Format("{0} was booked by you from {1} for {2}", booking.RoomName, booking.BookRangeLocalToString(aliceRequest.UserProfile.TimeZoneInfo), booking.BookedForToString());
}
catch (Exception ex)
{
response.StatusCode = System.Net.HttpStatusCode.BadRequest;
response.Message = ex.Message;
}

return response;
}
}
}
26 changes: 2 additions & 24 deletions RoomBookingLib/AliceRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,8 @@ public IAliceResponse Handle(IAliceRequest request)
string serverAction = request.ServerAction.ToLower();
IInternalRequestHandler handler = null;

switch (serverAction)
{
case "listrooms":
handler = new AliceListRoomsRequestHandler(_roomRepository);
break;
case "listbookings":
handler = new AliceBookingListRequestHandler(_bookingRepository);
break;
case "listmybookings":
handler = new AliceMyBookingListRequestHandler(_bookingRepository);
break;
case "bookroom":
handler = new AliceBookRoomRequestHandler(_bookingRepository);
break;
case "cancelbooking":
handler = new AliceCancelBookingRequestHandler(_bookingRepository);
break;
case "suggestcancellations":
handler = new AliceCancelBookingSuggestionRequestHandler(_bookingRepository);
break;
default:
handler = new AliceUnrecognizedRequestHandler();
break;
}
InternalRequestHandlerFactory factory = new InternalRequestHandlerFactory(_bookingRepository, _roomRepository);
handler = factory.GetInternalRequestHandler(serverAction);

IAliceResponse response;
response = handler.Handle(request);
Expand Down
37 changes: 37 additions & 0 deletions RoomBookingLib/InternalRequestHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RoomBookingExtension
{
class InternalRequestHandlerFactory
{
private BookingRepository _bookingRepository;
private RoomRepository _roomRepository;
private Dictionary<string, Func<IInternalRequestHandler>> _handlers;

public InternalRequestHandlerFactory(BookingRepository bookingRepository, RoomRepository roomRepository)
{
_bookingRepository = bookingRepository;
_roomRepository = roomRepository;
_handlers = new Dictionary<string, Func<IInternalRequestHandler>>();

_handlers.Add("listrooms", () => { return new AliceListRoomsRequestHandler(_roomRepository); });
_handlers.Add("listbookings", () => { return new AliceBookingListRequestHandler(_bookingRepository); });
_handlers.Add("listmybookings", () => { return new AliceMyBookingListRequestHandler(_bookingRepository); });
_handlers.Add("bookroom", () => { return new AliceBookRoomRequestHandler(_bookingRepository); });
_handlers.Add("cancelbooking", () => { return new AliceCancelBookingRequestHandler(_bookingRepository); });
_handlers.Add("suggestcancellations", () => { return new AliceCancelBookingSuggestionRequestHandler(_bookingRepository); });
_handlers.Add("unrecognized", () => { return new AliceUnrecognizedRequestHandler(); });
}

public IInternalRequestHandler GetInternalRequestHandler(string requestText)
{
if (_handlers.ContainsKey(requestText))
return _handlers[requestText]();

return _handlers["unrecognized"]();
}
}
}
2 changes: 2 additions & 0 deletions RoomBookingLib/RoomBookingExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
<Compile Include="AliceBookingCancellationSuggestionsParser.cs" />
<Compile Include="AliceBookingListParser.cs" />
<Compile Include="AliceBookingListRequestHandler.cs" />
<Compile Include="AliceRepeatBookingRequestHandler.cs" />
<Compile Include="AliceBookRoomRequestHandler.cs" />
<Compile Include="AliceCancelBookingRequestHandler.cs" />
<Compile Include="AliceCancelBookingSuggestionRequestHandler.cs" />
<Compile Include="AliceListRoomsRequestHandler.cs" />
<Compile Include="AliceMyBookingListRequestHandler.cs" />
<Compile Include="AliceRequestHandler.cs" />
<Compile Include="AliceListRoomParser.cs" />
<Compile Include="InternalRequestHandlerFactory.cs" />
<Compile Include="AliceUnrecognizedRequestHandler.cs" />
<Compile Include="BookingFilter.cs" />
<Compile Include="Booking.cs" />
Expand Down
2 changes: 1 addition & 1 deletion TestWebApp/AliceInterface/alice-chat.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
<div id="responseBox">
</div>
<input id="chatBox" placeholder="Ask something..." type="text" autocomplete="off" />
<textarea id="chatBox" placeholder="Ask something..." ></textarea>
</div>
<div style="display: none">
<div id="userMessage">
Expand Down
5 changes: 5 additions & 0 deletions TestWebApp/AliceInterface/contents/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
padding:0px; margin:0px;
font-family: Verdana;
}
textarea {
font-family: Verdana;
}
#content {

}
Expand Down Expand Up @@ -56,6 +59,8 @@
border: none;
border-radius: 6px;
background-color: #eee;
resize:none;
overflow:hidden;
}
#chatBox:hover, #chatBox:focus {
background-color: #e0e0e0;
Expand Down
11 changes: 7 additions & 4 deletions TestWebApp/AliceInterface/contents/js/keyboard-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
this.chatBox = null;
this.postRequestCallBack = null;
this.recentMessageQueue = null;
this.postMessageOnEnterKey = true;
}

KeyBoardHandler.prototype.handle = function () {
Expand All @@ -10,17 +11,19 @@ KeyBoardHandler.prototype.handle = function () {

KeyBoardHandler.prototype.attachChatBoxKeyboardEvent = function() {
var sender = this;
this.chatBox.keydown(function (event) {
this.chatBox.keyup(function (event) {
sender.handleChatBoxKeyboardEvent(sender, event);
});
}

KeyBoardHandler.prototype.handleChatBoxKeyboardEvent = function (sender, event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode === 13) {
var message = sender.chatBox.val();
sender.postRequestCallBack(message);
sender.chatBox.val("");
if (sender.postMessageOnEnterKey && event.shiftKey === false) {
var message = sender.chatBox.val();
sender.postRequestCallBack(message);
sender.chatBox.val("");
}
}
else if (keycode === 38) {
var message = sender.recentMessageQueue.Previous();
Expand Down
10 changes: 10 additions & 0 deletions TestWebApp/App_Data/AliceRequests/RoomBookingRequests.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@
"ServerAction": "BookRoom",
"MatchingPattern": "regex"
},
/*
Message: repeat booking on 12-12,tomorrow,12/12
Pattern: \b(repeat\sbooking\son\s)([A-Za-z0-9-,/\s]*)\b
*/
{
"UserMessage": "\\b(repeat\\sbooking\\son\\s)([A-Za-z0-9-,/\\s]*)\\b",
"ActionSuccessResponse": "Booked",
"ServerAction": "RepeatLastBooking",
"MatchingPattern": "regex"
},

{
"UserMessage": "cancel|cancel booking|cancel bookings|cancel my booking|cancel my bookings",
Expand Down
2 changes: 1 addition & 1 deletion TestWebApp/App_Data/AliceRequests/unhandledMessages.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"UserMessage":"how are you","InstanceCount":3},{"UserMessage":"Cancel my booking on 22 from 4 of room 1","InstanceCount":3},{"UserMessage":"tes 2","InstanceCount":1},{"UserMessage":"test 3","InstanceCount":2},{"UserMessage":"1","InstanceCount":1},{"UserMessage":"2","InstanceCount":1},{"UserMessage":"3","InstanceCount":1},{"UserMessage":"4","InstanceCount":1},{"UserMessage":"5","InstanceCount":1},{"UserMessage":"6","InstanceCount":1},{"UserMessage":"7","InstanceCount":1},{"UserMessage":"8","InstanceCount":1},{"UserMessage":"9","InstanceCount":1},{"UserMessage":"10","InstanceCount":1},{"UserMessage":"how a you?","InstanceCount":1},{"UserMessage":"how you","InstanceCount":1},{"UserMessage":"who wrote invisible man","InstanceCount":1},{"UserMessage":"sho rooms","InstanceCount":1},{"UserMessage":"show rooms","InstanceCount":5},{"UserMessage":"lst rum","InstanceCount":1},{"UserMessage":"cancel ","InstanceCount":1},{"UserMessage":"cancel booking for koln from 1","InstanceCount":1},{"UserMessage":"show","InstanceCount":1},{"UserMessage":"room","InstanceCount":1},{"UserMessage":"show all bookings","InstanceCount":1},{"UserMessage":"am i mad","InstanceCount":1},{"UserMessage":"have i gone mad","InstanceCount":2},{"UserMessage":"have i gone mad?","InstanceCount":1},{"UserMessage":"book rum","InstanceCount":1},{"UserMessage":"try","InstanceCount":1},{"UserMessage":"my","InstanceCount":1},{"UserMessage":"book amsterdam from 1 2","InstanceCount":1},{"UserMessage":"book amsterdam from 1 - 2","InstanceCount":1},{"UserMessage":"something","InstanceCount":1},{"UserMessage":"Im fine","InstanceCount":1},{"UserMessage":"sdf","InstanceCount":2},{"UserMessage":"zxc","InstanceCount":1},{"UserMessage":"book random from 1am","InstanceCount":1},{"UserMessage":"List rooms","InstanceCount":1},{"UserMessage":"alice","InstanceCount":1},{"UserMessage":"show booking","InstanceCount":1},{"UserMessage":"yes","InstanceCount":1},{"UserMessage":"tes","InstanceCount":1},{"UserMessage":"?","InstanceCount":1}]
[{"UserMessage":"test\n","InstanceCount":2},{"UserMessage":"tes","InstanceCount":1},{"UserMessage":"ho r u","InstanceCount":1},{"UserMessage":"how r u","InstanceCount":1},{"UserMessage":"h r u","InstanceCount":1},{"UserMessage":"book \ntest","InstanceCount":1},{"UserMessage":"a\nb\nc\n","InstanceCount":1},{"UserMessage":"enter","InstanceCount":1},{"UserMessage":"entre\nenter","InstanceCount":1}]
2 changes: 1 addition & 1 deletion TestWebApp/App_Data/RoomBookings/Bookings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"RoomName":"Utrecht","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:50:50.3554925+05:30"},{"RoomName":"Hamberg","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:50:56.9470091+05:30"},{"RoomName":"Eindhoven","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:51:00.0259062+05:30"},{"RoomName":"Koln","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:53:34.1576857+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-25T18:00:00Z","BookedToUtc":"2019-06-25T18:14:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T22:20:07.6721796+05:30"},{"RoomName":"Eindhoven","BookedFromUtc":"2019-06-25T19:30:00Z","BookedToUtc":"2019-06-25T20:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting","BookedOnUtc":"2019-06-26T00:17:33.9101279+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-29T12:30:00Z","BookedToUtc":"2019-06-29T13:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-29T16:10:27.6405683+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-29T13:30:00Z","BookedToUtc":"2019-06-29T14:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-29T16:11:26.9658733+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-29T14:30:00Z","BookedToUtc":"2019-06-29T15:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-29T16:13:16.5651628+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-08-01T08:00:00Z","BookedToUtc":"2019-08-01T08:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting","BookedOnUtc":"2019-07-13T22:33:11.3796367+05:30"},{"RoomName":"Amsterdam","BookedFromUtc":"2019-07-24T17:00:00Z","BookedToUtc":"2019-07-24T17:19:59.999Z","BookedBy":"Marco","BookedFor":"meeting","BookedOnUtc":"2019-07-24T22:23:57.3921834+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-07-28T08:00:00Z","BookedToUtc":"2019-07-28T08:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-07-28T01:11:51.8623266+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-07-28T08:30:00Z","BookedToUtc":"2019-07-28T09:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-07-28T01:12:37.7513864+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-07-28T09:30:00Z","BookedToUtc":"2019-07-28T10:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-07-28T01:12:50.2641775+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2020-04-01T08:00:00Z","BookedToUtc":"2020-04-01T08:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting","BookedOnUtc":"2019-07-29T00:18:19.3194253+05:30"}]
[{"RoomName":"Utrecht","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:50:50.3554925+05:30"},{"RoomName":"Hamberg","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:50:56.9470091+05:30"},{"RoomName":"Eindhoven","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:51:00.0259062+05:30"},{"RoomName":"Koln","BookedFromUtc":"2019-06-24T19:30:00Z","BookedToUtc":"2019-06-24T20:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T00:53:34.1576857+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-25T18:00:00Z","BookedToUtc":"2019-06-25T18:14:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-25T22:20:07.6721796+05:30"},{"RoomName":"Eindhoven","BookedFromUtc":"2019-06-25T19:30:00Z","BookedToUtc":"2019-06-25T20:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting","BookedOnUtc":"2019-06-26T00:17:33.9101279+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-29T12:30:00Z","BookedToUtc":"2019-06-29T13:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-29T16:10:27.6405683+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-29T13:30:00Z","BookedToUtc":"2019-06-29T14:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-29T16:11:26.9658733+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-06-29T14:30:00Z","BookedToUtc":"2019-06-29T15:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-06-29T16:13:16.5651628+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-08-01T08:00:00Z","BookedToUtc":"2019-08-01T08:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting","BookedOnUtc":"2019-07-13T22:33:11.3796367+05:30"},{"RoomName":"Amsterdam","BookedFromUtc":"2019-07-24T17:00:00Z","BookedToUtc":"2019-07-24T17:19:59.999Z","BookedBy":"Marco","BookedFor":"meeting","BookedOnUtc":"2019-07-24T22:23:57.3921834+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-07-28T08:00:00Z","BookedToUtc":"2019-07-28T08:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-07-28T01:11:51.8623266+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-07-28T08:30:00Z","BookedToUtc":"2019-07-28T09:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-07-28T01:12:37.7513864+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2019-07-28T09:30:00Z","BookedToUtc":"2019-07-28T10:29:59.999Z","BookedBy":"Vinod","BookedFor":null,"BookedOnUtc":"2019-07-28T01:12:50.2641775+05:30"},{"RoomName":"amsterdam","BookedFromUtc":"2020-04-01T08:00:00Z","BookedToUtc":"2020-04-01T08:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting","BookedOnUtc":"2019-07-29T00:18:19.3194253+05:30"},{"RoomName":"Training room","BookedFromUtc":"2019-08-02T04:30:00Z","BookedToUtc":"2019-08-02T05:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting","BookedOnUtc":"2019-08-01T23:37:05.4517359+05:30"},{"RoomName":"training room","BookedFromUtc":"2019-08-02T08:00:00Z","BookedToUtc":"2019-08-02T08:29:59.999Z","BookedBy":"Vinod","BookedFor":"meeting on code quality","BookedOnUtc":"2019-08-01T23:51:04.7185742+05:30"}]

0 comments on commit e0eff4c

Please sign in to comment.