-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
739 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
build: | ||
dep ensure | ||
GOOS=linux go build -o bin/telegram telegram/main.go | ||
GOOS=linux go build -o bin/telegram_lambda cmd/telegram/lambda/main.go | ||
GOOS=linux go build -o bin/telegram_http cmd/telegram/http/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# WhosInBot Plan | ||
|
||
|
||
## Package whosinbot | ||
WhosInBot | ||
DataStore DataStore | ||
HandleCommand(command Command) (Response, Error) | ||
|
||
## Package whosinbot/domain | ||
Command struct | ||
name string | ||
params string[] | ||
|
||
Response struct | ||
message string | ||
|
||
RollCall struct | ||
ChatID string | ||
Title string | ||
|
||
RollCallResponse struct | ||
ChatID int64 | ||
UserID int64 | ||
Response string | ||
Reasons string | ||
|
||
DataStore interface | ||
SetRollCall(RollCall) | ||
DeleteRollCall(RollCall) | ||
SetResponse(RollCallResponse) | ||
DeleteResponse(RollCallResponse) | ||
## Package whosinbot/dynamodb | ||
DynamoDataStore | ||
SetRollCall(RollCall) | ||
DeleteRollCall(RollCall) | ||
SetResponse(RollCallResponse) | ||
DeleteResponse(RollCallResponse) | ||
NewDynamoDataStore(DynamoConfig) | ||
|
||
## Package whoinbot/helpers | ||
Helpers | ||
|
||
## Package telegram | ||
NewTelegram(TelegramConfig) | ||
Telegram | ||
BotApi | ||
ParseUpdateRequest(string) (Command, error) | ||
SendMessage(Response) (error) | ||
|
||
## Package cmd/telegram_lambda | ||
Main | ||
LoadDynamoConfig | ||
LoadTelegramConfig | ||
|
||
## Package cmd/telegram_http | ||
Main | ||
LoadDynamoConfig | ||
LoadTelegramConfig | ||
LoadHttpConfig | ||
|
||
##Package whosinbot/config | ||
TelegramConfig | ||
HttpConfig | ||
DynamoConfig | ||
|
||
|
||
## Commands | ||
- start_roll_call (title) | ||
- in (reason) | ||
- out (reason) | ||
- set_title (title) | ||
- set_in_for (name) | ||
- end_roll_call | ||
- ssh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/col/whosinbot/dynamodb" | ||
"net/http" | ||
"fmt" | ||
"github.com/col/whosinbot/whosinbot" | ||
whttp "github.com/col/whosinbot/http" | ||
) | ||
|
||
func main() { | ||
dataStore := &dynamodb.DynamoDataStore{} | ||
bot := &whosinbot.WhosInBot{ DataStore: dataStore } | ||
|
||
http.Handle("/webhook", &whttp.WebhookHandler{WhosInBot: bot}) | ||
port := 8080 | ||
serverConfig := fmt.Sprintf(":%d", port) | ||
http.ListenAndServe(serverConfig, nil) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/col/whosinbot/dynamodb" | ||
"context" | ||
"github.com/col/whosinbot/telegram" | ||
"github.com/col/whosinbot/whosinbot" | ||
) | ||
|
||
func main() { | ||
lambda.Start(Handler) | ||
} | ||
|
||
func Handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | ||
|
||
// Parse Command | ||
command, err := telegram.ParseUpdate([]byte(request.Body)) | ||
if err != nil { | ||
return events.APIGatewayProxyResponse{StatusCode: 400}, err | ||
} | ||
|
||
// Process Command | ||
dataStore := &dynamodb.DynamoDataStore{} | ||
bot := whosinbot.WhosInBot{ DataStore: dataStore } | ||
response, err := bot.HandleCommand(command) | ||
if err != nil { | ||
return events.APIGatewayProxyResponse{StatusCode: 400}, err | ||
} | ||
|
||
// Send Response | ||
api := telegram.NewTelegram(request.PathParameters["token"]) | ||
err = api.SendResponse(response) | ||
if err != nil { | ||
return events.APIGatewayProxyResponse{StatusCode: 400}, err | ||
} | ||
|
||
return events.APIGatewayProxyResponse{StatusCode: 200}, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package domain | ||
|
||
import "strings" | ||
|
||
type Command struct { | ||
ChatID int64 | ||
Name string | ||
Params []string | ||
From User | ||
} | ||
|
||
func (c Command) ParamsString() string { | ||
return strings.Join(c.Params, " ") | ||
} | ||
|
||
type User struct { | ||
UserID int64 | ||
Username string | ||
} | ||
|
||
func EmptyCommand() Command { | ||
return Command{ | ||
ChatID: 0, | ||
Name: "", | ||
Params: nil, | ||
From: User{}, | ||
} | ||
} | ||
|
||
type Response struct { | ||
ChatID int64 | ||
Text string | ||
} | ||
|
||
type DataStore interface { | ||
StartRollCall(rollCall RollCall) error | ||
EndRollCall(rollCall RollCall) error | ||
|
||
SetResponse(rollCallResponse RollCallResponse) error | ||
|
||
GetRollCall(chatID int64) (*RollCall, error) | ||
} | ||
|
||
type RollCall struct { | ||
ChatID int64 | ||
Title string | ||
In []RollCallResponse | ||
Out []RollCallResponse | ||
Maybe []RollCallResponse | ||
} | ||
|
||
type RollCallResponse struct { | ||
ChatID int64 | ||
UserID int64 | ||
Name string | ||
Response string | ||
Reason string | ||
} |
Oops, something went wrong.