Skip to content

Commit

Permalink
Merge pull request #4617 from activepieces/fix/telegram2
Browse files Browse the repository at this point in the history
feat(telegram): merge two prs into same one
  • Loading branch information
abuaboud committed May 3, 2024
2 parents 634756f + f903768 commit 03e0529
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/telegram-bot/package.json
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-telegram-bot",
"version": "0.3.13"
"version": "0.3.14"
}
Expand Up @@ -56,6 +56,12 @@ export const telegramSendMessageAction = createAction({
instructions_format: Property.MarkDown({
value: format,
}),
web_page_preview: Property.Checkbox({
displayName: 'Disable Web Page Preview',
description: 'Disable link previews for links in this message',
required: false,
defaultValue: false,
}),
message: Property.LongText({
displayName: 'Message',
description: 'The message to be sent',
Expand All @@ -78,6 +84,7 @@ export const telegramSendMessageAction = createAction({
message_thread_id: ctx.propsValue['message_thread_id'] ?? undefined,
parse_mode: ctx.propsValue['format'] ?? 'MarkdownV2',
reply_markup: ctx.propsValue['reply_markup'] ?? undefined,
disable_web_page_preview: ctx.propsValue['web_page_preview'] ?? false,
},
});
},
Expand Down
@@ -1,6 +1,7 @@
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { telegramCommons } from '../common';
import { telegramBotAuth } from '../..';
import { httpClient, HttpMethod, HttpRequest } from '@activepieces/pieces-common';

export const telegramNewMessage = createTrigger({
auth: telegramBotAuth,
Expand Down Expand Up @@ -45,5 +46,18 @@ export const telegramNewMessage = createTrigger({
},
async run(context) {
return [context.payload.body];
}
},
async test(context) {
const messages = await getLastFiveMessages(context.auth)
return messages.result
},
});

const getLastFiveMessages = async (botToken: string) => {
const request: HttpRequest = {
method: HttpMethod.GET,
url: `https://api.telegram.org/bot${botToken}/getUpdates?offset=-5`,
};
const response = await httpClient.sendRequest(request);
return response.body;
}

0 comments on commit 03e0529

Please sign in to comment.