-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
20d3318
commit a77d156
Showing
13 changed files
with
254 additions
and
128 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -17,4 +17,5 @@ | |
# Development artifacts | ||
dev.env | ||
jarvis | ||
utilities | ||
__debug_bin |
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
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
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,58 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | ||
) | ||
|
||
func JarvisRouter(bot *tgbotapi.BotAPI) *gin.Engine { | ||
router := gin.Default() | ||
|
||
router.Use(BotContext(bot)) | ||
router.Use(AugustHttpClientContext()) | ||
|
||
// Static | ||
router.StaticFile("robots.txt", "./static/robots.txt") | ||
|
||
router.GET("/health", health) | ||
// Knocks | ||
router.POST("/welcome/:invite_code", welcome) | ||
router.POST("/trustedknock", Auth(), trustedKnock) | ||
|
||
return router | ||
} | ||
|
||
func health(c *gin.Context) { | ||
c.String(http.StatusOK, "healthy") | ||
} | ||
|
||
func trustedKnock(c *gin.Context) { | ||
// Protected by 'TrustedHmacAuthentication' middleware | ||
authenticatedUser := c.MustGet("authenticatedUser").(string) | ||
|
||
august := c.MustGet(AUGUST_HTTP_CONTEXT).(*AugustHttpClient) | ||
|
||
error := august.OperateLock("unlock") | ||
if error != nil { | ||
fmt.Println(fmt.Errorf("failed to unlock August: %s", error)) | ||
c.AbortWithStatus(http.StatusInternalServerError) | ||
} | ||
|
||
// Accept if we have not aborted. | ||
if !c.IsAborted() { | ||
c.String(http.StatusAccepted, fmt.Sprintf("Welcome, %s.", authenticatedUser)) | ||
} | ||
} | ||
|
||
func welcome(c *gin.Context) { | ||
|
||
bot := c.MustGet(BOT_CONTEXT).(*BotExtended) | ||
invite_code := c.Param("invite_code") | ||
|
||
// TODO | ||
bot.SendMessageToPrimaryTelegramGroup(fmt.Sprintf("Welcome %s", invite_code)) | ||
c.String(http.StatusAccepted, "Welcome, "+invite_code) | ||
} |
Oops, something went wrong.