Skip to content

Commit

Permalink
feat(Telegram Node): Add support for local bot api server (#8437)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Bennetts <[email protected]>
  • Loading branch information
ddzobov and Joffcom authored May 20, 2024
1 parent 747012d commit 87f965e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ export const credentialTypeTelegram = {
description:
'Chat with the <a href="https://telegram.me/botfather">bot father</a> to obtain the access token',
},
{
displayName: 'Base URL',
name: 'baseUrl',
type: 'string',
default: 'https://api.telegram.org',
description: 'Base URL for Telegram Bot API',
},
],
test: {
request: {
baseURL: '=https://api.telegram.org/bot{{$credentials.accessToken}}',
baseURL: '={{$credentials.baseUrl}}/bot{{$credentials.accessToken}}',
url: '/getMe',
},
},
Expand Down
9 changes: 8 additions & 1 deletion packages/nodes-base/credentials/TelegramApi.credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ export class TelegramApi implements ICredentialType {
description:
'Chat with the <a href="https://telegram.me/botfather">bot father</a> to obtain the access token',
},
{
displayName: 'Base URL',
name: 'baseUrl',
type: 'string',
default: 'https://api.telegram.org',
description: 'Base URL for Telegram Bot API',
},
];

test: ICredentialTestRequest = {
request: {
baseURL: '=https://api.telegram.org/bot{{$credentials.accessToken}}',
baseURL: '={{$credentials.baseUrl}}/bot{{$credentials.accessToken}}',
url: '/getMe',
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Telegram/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export async function apiRequest(
const options: IRequestOptions = {
headers: {},
method,
uri: `https://api.telegram.org/bot${credentials.accessToken}/${endpoint}`,
uri: `${credentials.baseUrl}/bot${credentials.accessToken}/${endpoint}`,
body,
qs: query,
json: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Telegram/Telegram.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ export class Telegram implements INodeType {
{
json: false,
encoding: null,
uri: `https://api.telegram.org/file/bot${credentials.accessToken}/${filePath}`,
uri: `${credentials.baseUrl}/bot${credentials.accessToken}/${filePath}`,

This comment has been minimized.

Copy link
@GuilhermeBarile

GuilhermeBarile May 20, 2024

Contributor

There is a typo here, /file was removed from the URL

resolveWithFullResponse: true,
useStream: true,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Telegram/TelegramTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class TelegramTrigger implements INodeType {
{
json: false,
encoding: null,
uri: `https://api.telegram.org/file/bot${credentials.accessToken}/${file_path}`,
uri: `${credentials.baseUrl}/file/bot${credentials.accessToken}/${file_path}`,
resolveWithFullResponse: true,
},
);
Expand Down

1 comment on commit 87f965e

@jiangzaivip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, how do I use this?

Please sign in to comment.