Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9f29616
add copyMessage method
LetItCode Jan 8, 2021
52d31f8
duplicate assignment
LetItCode Jan 8, 2021
8146103
add context copyMessage typings
LetItCode Jan 8, 2021
d7dd5e5
Merge branch 'master' of https://github.com/LetItCode/telegraf
LetItCode Jan 8, 2021
1efd566
Bot API 5.0 - Webhooks
LetItCode Jan 14, 2021
909f337
Bot API 5.0 - unbanChatMember
LetItCode Jan 14, 2021
5dd9bda
add sendDocument params
LetItCode Jan 14, 2021
e81dadb
add param to unpinChatMessage
LetItCode Jan 14, 2021
281bd15
Bot API 5.0 - unpinAllChatMessages
LetItCode Jan 14, 2021
b6cacbb
correct params in sendMediaGroup
LetItCode Jan 14, 2021
1389203
correct params in sendLocation
LetItCode Jan 14, 2021
beab76e
Use typegram instead of telegram-typings
Loskir Jan 14, 2021
f46b2d9
Fix: add reexport
Loskir Jan 14, 2021
611b91d
Fix JSDoc for promoteChatMember
Loskir Jan 14, 2021
0810733
missing space
LetItCode Jan 14, 2021
498308e
correct params in editMessageLiveLocation
LetItCode Jan 14, 2021
b74fc7a
Merge branch 'master' of https://github.com/LetItCode/telegraf
LetItCode Jan 14, 2021
c88c326
Remove IncomingMessage
Loskir Jan 14, 2021
74b511b
Merge branch 'typegram'
Loskir Jan 14, 2021
3b320a9
Add emoji param to ExtraDice
Loskir Jan 14, 2021
b32ea34
its ok ...undefined
LetItCode Jan 14, 2021
10ce5c9
Merge branch 'master' of https://github.com/LetItCode/telegraf
LetItCode Jan 14, 2021
b7f2852
correct params in promoteChatMember
LetItCode Jan 14, 2021
6fd65b7
Change max poll question length to 300
Loskir Jan 14, 2021
fc86259
Fix test for sendVideoNote
Loskir Jan 14, 2021
22d4e5d
Fix test for editMessageLiveLocation
Loskir Jan 14, 2021
b1286d9
add copyMessage method
LetItCode Jan 14, 2021
ef7b1ef
convert sendCopy to proxy method 😥 bb replicators
LetItCode Jan 14, 2021
d9e189e
Revert "convert sendCopy to proxy method 😥 bb replicators"
LetItCode Jan 14, 2021
86196a1
sendCopy via proxy method
LetItCode Jan 14, 2021
c2c3174
Update typings for Extra
Loskir Jan 14, 2021
318d88f
Update typings for quiz
Loskir Jan 14, 2021
4136de4
Fix typings for poll
Loskir Jan 14, 2021
35e37d2
native copy message & online require
LetItCode Jan 14, 2021
eb96e8f
rewrite editMessageMedia
deletedev Jan 14, 2021
a4c5f12
fixes
deletedev Jan 14, 2021
267bafb
Fix typing for EditMessageMediaPayload
Loskir Jan 15, 2021
af7f7f2
Fix JSDoc
Loskir Jan 15, 2021
eea947b
Lint
Loskir Jan 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions context.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,17 @@ class TelegrafContext {
editMessageMedia (media, extra) {
this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageMedia')
return this.inlineMessageId
? this.telegram.editMessageMedia(
undefined,
undefined,
this.inlineMessageId,
? this.telegram.editMessageMedia({
inline_message_id: this.inlineMessageId,
media,
extra
)
: this.telegram.editMessageMedia(
this.chat.id,
this.callbackQuery.message.message_id,
undefined,
reply_markup: extra.reply_markup ? extra.reply_markup : extra
})
: this.telegram.editMessageMedia({
chat_id: this.chat.id,
message_id: this.callbackQuery.message.message_id,
media,
extra
)
reply_markup: extra.reply_markup ? extra.reply_markup : extra
})
}

editMessageReplyMarkup (markup) {
Expand All @@ -272,7 +269,7 @@ class TelegrafContext {
)
}

editMessageLiveLocation (latitude, longitude, markup) {
editMessageLiveLocation (latitude, longitude, markup, extra) {
this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageLiveLocation')
return this.inlineMessageId
? this.telegram.editMessageLiveLocation(
Expand All @@ -281,15 +278,17 @@ class TelegrafContext {
undefined,
undefined,
this.inlineMessageId,
markup
markup,
extra
)
: this.telegram.editMessageLiveLocation(
latitude,
longitude,
this.chat.id,
this.callbackQuery.message.message_id,
undefined,
markup
markup,
extra
)
}

Expand Down Expand Up @@ -380,6 +379,11 @@ class TelegrafContext {
return this.telegram.unpinChatMessage(this.chat.id, ...args)
}

unpinAllChatMessages () {
this.assert(this.chat, 'unpinAllChatMessages')
return this.telegram.unpinAllChatMessages(this.chat.id)
}

leaveChat (...args) {
this.assert(this.chat, 'leaveChat')
return this.telegram.leaveChat(this.chat.id, ...args)
Expand Down Expand Up @@ -590,6 +594,16 @@ class TelegrafContext {
this.assert(message, 'forwardMessage')
return this.telegram.forwardMessage(chatId, this.chat.id, message.message_id, extra)
}

copyMessage (chatId, extra) {
const message = this.message ||
this.editedMessage ||
this.channelPost ||
this.editedChannelPost ||
(this.callbackQuery && this.callbackQuery.message)
this.assert(message, 'copyMessage')
return this.telegram.copyMessage(chatId, message.chat.id, message.message_id, extra)
}
}

module.exports = TelegrafContext
41 changes: 35 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ Context shortcuts for **message** update:
| `setStickerSetThumb` | [`telegram.setStickerSetThumb`](#setstickersetthumb) |
| `stopPoll` | [`telegram.stopPoll`](#stoppoll) |
| `unpinChatMessage` | [`telegram.unpinChatMessage`](#unpinchatmessage) |
| `unpinAllChatMessages` | [`telegram.unpinAllChatMessages`](#unpinallchatmessages) |
| `uploadStickerFile` | [`telegram.uploadStickerFile`](#uploadstickerfile) |
| `unbanChatMember` | [`telegram.unbanChatMember`](#unbanchatmember) |

Expand Down Expand Up @@ -332,6 +333,7 @@ Context shortcuts for **callback_query** update:
| `setStickerSetThumb` | [`telegram.setStickerSetThumb`](#setstickersetthumb) |
| `stopPoll` | [`telegram.stopPoll`](#stoppoll) |
| `unpinChatMessage` | [`telegram.unpinChatMessage`](#unpinchatmessage) |
| `unpinAllChatMessages` | [`telegram.unpinAllChatMessages`](#unpinallchatmessages) |
| `uploadStickerFile` | [`telegram.uploadStickerFile`](#uploadstickerfile) |
| `unbanChatMember` | [`telegram.unbanChatMember`](#unbanchatmember) |

Expand Down Expand Up @@ -1440,6 +1442,7 @@ Use this method to edit live location messages sent by the bot or via the bot.
| messageId | `string` | Message id |
| inlineMessageId | `string` | Inline message id |
| [markup] | `object` | Keyboard markup |
| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#editmessagelivelocation)|

##### editMessageReplyMarkup

Expand Down Expand Up @@ -1482,7 +1485,6 @@ Forwards message.
| messageId | `number` | Message id |
| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#forwardmessage)|


##### sendCopy

Sends message copy.
Expand All @@ -1495,6 +1497,19 @@ Sends message copy.
| message | `object` | Message |
| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#sendmessage)|

##### copyMessage

Use this method to copy messages of any kind.

`telegram.copyMessage(chatId, message, [extra]) => Promise`

| Param | Type | Description |
| --- | --- | --- |
| chatId | `number/string` | Target Chat id |
| fromChatId | `number/string` | Source Chat id |
| messageId | `number` | Message id |
| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#copymessage)|

##### getWebhookInfo

Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
Expand Down Expand Up @@ -1786,6 +1801,18 @@ Use this method to unpin a message in a supergroup chat.
`telegram.unpinChatMessage(chatId) => Promise`
[Official documentation](https://core.telegram.org/bots/api#unpinchatmessage)

| Param | Type | Description |
| --- | --- | --- |
| chatId | `number/string` | Chat id |
| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#unpinchatmessage)|

##### unpinAllChatMessages

Use this method to clear the list of pinned messages in a chat

`telegram.unpinAllChatMessages(chatId) => Promise`
[Official documentation](https://core.telegram.org/bots/api#unpinallchatmessages)

| Param | Type | Description |
| --- | --- | --- |
| chatId | `number/string` | Chat id |
Expand All @@ -1808,6 +1835,10 @@ Removes webhook integration.
`telegram.deleteWebhook() => Promise`
[Official documentation](https://core.telegram.org/bots/api#deletewebhook)

| Param | Type | Description |
| --- | --- | --- |
| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#deletewebhook) |

##### sendAudio

Sends audio.
Expand Down Expand Up @@ -2106,15 +2137,13 @@ Use this method to upload a .png file with a sticker for later use in createNewS

Specifies an url to receive incoming updates via an outgoing webhook.

`telegram.setWebhook(url, [cert], [maxConnections], [allowedUpdates]) => Promise`
`telegram.setWebhook(url, [extra]) => Promise`
[Official documentation](https://core.telegram.org/bots/api#setwebhook)

| Param | Type | Description |
| --- | --- | --- |
| url | `string` | Public url for webhook |
| [cert] | `File` | SSL public certificate |
| [maxConnections] | `number` | Maximum allowed number of simultaneous HTTPS connections to the webhook |
| [allowedUpdates] | `string[]` | List the types of updates you want your bot to receive |
| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#setwebhook) |

##### unbanChatMember

Expand All @@ -2127,7 +2156,7 @@ Use this method to unban a previously kicked user in a supergroup.
| --- | --- | --- |
| chatId | `number/string` | Chat id |
| userId | `number` | User id |

| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#unbanchatmember) |

##### setPassportDataErrors

Expand Down
6 changes: 2 additions & 4 deletions docs/examples/echo-bot-module.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Modules documentation: https://telegraf.js.org/#/?id=telegraf-modules
// $> telegraf -t `BOT TOKEN` echo-bot-module.js
const Composer = require('telegraf/composer')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
const { Composer, Extra, Markup } = require('telegraf')

const keyboard = Markup.inlineKeyboard([
Markup.urlButton('❤️', 'http://telegraf.js.org'),
Expand Down Expand Up @@ -35,6 +33,6 @@ bot.help(async (ctx) => {
})
bot.action('delete', ({ deleteMessage }) => deleteMessage())
bot.on('dice', (ctx) => ctx.reply(`Value: ${ctx.message.dice.value}`))
bot.on('message', (ctx) => ctx.telegram.sendCopy(ctx.chat.id, ctx.message, Extra.markup(keyboard)))
bot.on('message', (ctx) => ctx.copyMessage(ctx.chat.id, Extra.markup(keyboard)))

module.exports = bot
6 changes: 2 additions & 4 deletions docs/examples/echo-bot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const Telegraf = require('telegraf')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
const { Telegraf, Extra, Markup } = require('../../telegraf')

const keyboard = Markup.inlineKeyboard([
Markup.urlButton('❤️', 'http://telegraf.js.org'),
Expand All @@ -10,6 +8,6 @@ const keyboard = Markup.inlineKeyboard([
const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start((ctx) => ctx.reply('Hello'))
bot.help((ctx) => ctx.reply('Help message'))
bot.on('message', (ctx) => ctx.telegram.sendCopy(ctx.chat.id, ctx.message, Extra.markup(keyboard)))
bot.on('message', (ctx) => ctx.copyMessage(ctx.chat.id, Extra.markup(keyboard)))
bot.action('delete', ({ deleteMessage }) => deleteMessage())
bot.launch()
7 changes: 4 additions & 3 deletions docs/examples/media-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ bot.command('edit_media', (ctx) => ctx.replyWithAnimation(AnimationUrl1, Extra.m
)))

bot.action('swap_media', (ctx) => ctx.editMessageMedia({
type: 'animation',
media: AnimationUrl2
}))
type: 'animation',
media: AnimationUrl2,
}
))

bot.launch()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"module-alias": "^2.2.2",
"node-fetch": "^2.2.0",
"sandwich-stream": "^2.0.1",
"telegram-typings": "^3.6.0"
"typegram": "^3.1.5"
},
"devDependencies": {
"@types/node": "^13.1.0",
Expand Down
52 changes: 29 additions & 23 deletions telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,12 @@ class Telegram extends ApiClient {
})
}

setWebhook (url, certificate, maxConnections, allowedUpdates) {
return this.callApi('setWebhook', {
url,
certificate,
max_connections: maxConnections,
allowed_updates: allowedUpdates
})
setWebhook (url, extra) {
return this.callApi('setWebhook', { url, ...extra })
}

deleteWebhook () {
return this.callApi('deleteWebhook')
deleteWebhook (extra) {
return this.callApi('deleteWebhook', extra)
}

sendMessage (chatId, text, extra) {
Expand Down Expand Up @@ -231,16 +226,20 @@ class Telegram extends ApiClient {
return this.callApi('pinChatMessage', { chat_id: chatId, message_id: messageId, ...extra })
}

unpinChatMessage (chatId) {
return this.callApi('unpinChatMessage', { chat_id: chatId })
unpinChatMessage (chatId, extra) {
return this.callApi('unpinChatMessage', { chat_id: chatId, ...extra })
}

unpinAllChatMessages (chatId) {
return this.callApi('unpinAllChatMessages', { chat_id: chatId })
}

leaveChat (chatId) {
return this.callApi('leaveChat', { chat_id: chatId })
}

unbanChatMember (chatId, userId) {
return this.callApi('unbanChatMember', { chat_id: chatId, user_id: userId })
unbanChatMember (chatId, userId, extra) {
return this.callApi('unbanChatMember', { chat_id: chatId, user_id: userId, ...extra })
}

answerCbQuery (callbackQueryId, text, showAlert, extra) {
Expand Down Expand Up @@ -297,14 +296,8 @@ class Telegram extends ApiClient {
})
}

editMessageMedia (chatId, messageId, inlineMessageId, media, extra = {}) {
return this.callApi('editMessageMedia', {
chat_id: chatId,
message_id: messageId,
inline_message_id: inlineMessageId,
media: { ...media, parse_mode: extra.parse_mode },
reply_markup: extra.reply_markup ? extra.reply_markup : extra
})
editMessageMedia (payload = {}) {
return this.callApi('editMessageMedia', payload)
}

editMessageReplyMarkup (chatId, messageId, inlineMessageId, markup) {
Expand All @@ -316,14 +309,15 @@ class Telegram extends ApiClient {
})
}

editMessageLiveLocation (latitude, longitude, chatId, messageId, inlineMessageId, markup) {
editMessageLiveLocation (latitude, longitude, chatId, messageId, inlineMessageId, markup, extra) {
return this.callApi('editMessageLiveLocation', {
latitude,
longitude,
chat_id: chatId,
message_id: messageId,
inline_message_id: inlineMessageId,
reply_markup: markup
reply_markup: markup,
...extra
})
}

Expand Down Expand Up @@ -417,6 +411,9 @@ class Telegram extends ApiClient {
if (!message) {
throw new Error('Message is required')
}
if (message.chat && message.chat.id && message.message_id) {
return this.copyMessage(chatId, message.chat.id, message.message_id, extra)
}
const type = Object.keys(replicators.copyMethods).find((type) => message[type])
if (!type) {
throw new Error('Unsupported message type')
Expand All @@ -428,6 +425,15 @@ class Telegram extends ApiClient {
}
return this.callApi(replicators.copyMethods[type], opts)
}

copyMessage (chatId, fromChatId, messageId, extra) {
return this.callApi('copyMessage', {
chat_id: chatId,
from_chat_id: fromChatId,
message_id: messageId,
...extra
})
}
}

module.exports = Telegram
4 changes: 4 additions & 0 deletions test/telegraf.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ test.cb('should provide shortcuts for `message` update', (t) => {
t.true('setChatDescription' in ctx)
t.true('pinChatMessage' in ctx)
t.true('unpinChatMessage' in ctx)
t.true('unpinAllChatMessages' in ctx)
t.true('leaveChat' in ctx)
t.true('getChatAdministrators' in ctx)
t.true('getChatMember' in ctx)
Expand All @@ -102,6 +103,7 @@ test.cb('should provide shortcuts for `message` update', (t) => {
t.true('editMessageLiveLocation' in ctx)
t.true('stopMessageLiveLocation' in ctx)
t.true('forwardMessage' in ctx)
t.true('copyMessage' in ctx)
t.end()
})
bot.handleUpdate({ message: BaseTextMessage })
Expand Down Expand Up @@ -141,6 +143,7 @@ test.cb('should provide shortcuts for `callback_query` update', (t) => {
t.true('setChatDescription' in ctx)
t.true('pinChatMessage' in ctx)
t.true('unpinChatMessage' in ctx)
t.true('unpinAllChatMessages' in ctx)
t.true('leaveChat' in ctx)
t.true('getChatAdministrators' in ctx)
t.true('getChatMember' in ctx)
Expand All @@ -156,6 +159,7 @@ test.cb('should provide shortcuts for `callback_query` update', (t) => {
t.true('editMessageLiveLocation' in ctx)
t.true('stopMessageLiveLocation' in ctx)
t.true('forwardMessage' in ctx)
t.true('copyMessage' in ctx)
t.end()
})
bot.handleUpdate({ callback_query: BaseTextMessage })
Expand Down
Loading