-
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.
Merge pull request #11 from jotacemarin/develop
History with ttl
- Loading branch information
Showing
18 changed files
with
155 additions
and
42 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
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,3 @@ | ||
{ | ||
"authorizationToken": "Basic S0dSYWZ2eVNxSTBoSm5vQVZuOHFqZzFRRkp3WEg4cFI6OjEyTUd6alhmeENEMmVTbGR3azdabXNiUWlRTHN6OTY1ZFhyZFJSSS0yR1U5V2kzdVpvLVY4bmN5Y3JFVEZLbEk=" | ||
"authorizationToken": "Basic MTM0NjU1NzA4NToyMmYzOTFkNS0xODcyLTRhZmItYTIxMS1hYjNiYmEyNGRlNjk=" | ||
} |
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,13 @@ | ||
name: ${self:custom.secrets.service.name}-${self:custom.secrets.provider.stage}-telegram-get-messages | ||
handler: index.telegramGetMessages | ||
memorySize: 128 | ||
timeout: 30 | ||
reservedConcurrency: 5 | ||
events: | ||
- http: | ||
path: /${self:custom.secrets.service.name}-${self:custom.secrets.provider.stage}/telegram/get-messages | ||
method: GET | ||
cors: true | ||
authorizer: | ||
name: telegramAuthorizer | ||
resultTtlInSeconds: 0 |
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,28 @@ | ||
import { APIGatewayEvent, Callback, Context } from "aws-lambda"; | ||
import { BAD_REQUEST, OK } from "http-status"; | ||
import { ChatMessageDao } from "../../lib/dao"; | ||
|
||
const execute = async (event: APIGatewayEvent): Promise<any> => { | ||
if (!event?.queryStringParameters?.chat_id) { | ||
return { statusCode: BAD_REQUEST }; | ||
} | ||
|
||
const chatId = Number(event.queryStringParameters.chat_id); | ||
|
||
await ChatMessageDao.initInstance(); | ||
const messages = await ChatMessageDao.getAll(chatId); | ||
|
||
return { statusCode: OK, body: JSON.stringify(messages) }; | ||
}; | ||
|
||
export const telegramGetMessages = async ( | ||
event: APIGatewayEvent, | ||
context: Context, | ||
callback: Callback | ||
): Promise<void> => { | ||
context.callbackWaitsForEmptyEventLoop = false; | ||
|
||
const response = await execute(event); | ||
|
||
return callback(null, response); | ||
}; |
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
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,52 @@ | ||
import { Model, Schema, model } from "mongoose"; | ||
import { ChatMessage } from "../models"; | ||
import { MongodbService } from "../services"; | ||
|
||
export class ChatMessageDao { | ||
private static schemaName: string = "chat_message"; | ||
private static chatMessageSchema: Schema<ChatMessage>; | ||
public static chatMessageModel: Model<ChatMessage>; | ||
|
||
private constructor() {} | ||
|
||
public static async initInstance() { | ||
await MongodbService.initInstance(); | ||
|
||
if (!ChatMessageDao.chatMessageSchema) { | ||
ChatMessageDao.chatMessageSchema = new Schema( | ||
{ | ||
telegramMessage: { type: Schema.Types.Mixed, required: true }, | ||
expireAt: { type: Schema.Types.Date, expires: 43200 }, | ||
}, | ||
{ | ||
timestamps: true, | ||
expireAfterSeconds: 43200, | ||
} | ||
); | ||
} | ||
|
||
if (!ChatMessageDao.chatMessageModel) { | ||
ChatMessageDao.chatMessageModel = model( | ||
ChatMessageDao.schemaName, | ||
ChatMessageDao.chatMessageSchema | ||
); | ||
} | ||
} | ||
|
||
public static async save( | ||
chatMessage: ChatMessage | ||
): Promise<ChatMessage | null> { | ||
return ChatMessageDao.chatMessageModel.create(chatMessage); | ||
} | ||
|
||
public static async getAll(chatId: Number): Promise<Array<ChatMessage>> { | ||
const chatMessages = await ChatMessageDao.chatMessageModel | ||
.find({ "telegramMessage.message.chat.id": chatId }) | ||
.exec(); | ||
if (!chatMessages || !chatMessages?.length) { | ||
return []; | ||
} | ||
|
||
return chatMessages; | ||
} | ||
} |
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,2 +1,3 @@ | ||
export { CommandDao } from "./commandDao"; | ||
export { UserDao } from "./userDao"; | ||
export { ChatMessageDao } from "./chatMessageDao"; |
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