Open AnthonyMouallem opened 4 years ago
You can send your messages with photo as text messages for testing purposes.
I have a simple solution for Telegraf Bot Framework.
const Telegraf = require('telegraf')
const TelegrafContext = require('telegraf/context')
class MyContext extends TelegrafContext {
replyWithPhoto (photo, ...extra) {
const { caption, ...rest } = extra[0]
this.assert(this.chat, 'reply')
const text = `[${photo}]\n${caption}`
return this.telegram.sendMessage(this.chat.id, text, rest)
}
}
const bot = new Telegraf("bot_token", {
telegram: {
apiRoot: server.ApiURL,
},
contextType: MyContext,
})
I saw that this package use express, so it will be possible to handle multipart requests but I'm not sure how to code, someone want to discuss some improvements to this library?
Hello @b3nab . Funny enough, I was just looking at implementing this feature into the library as it is required by me as well. Need to send photos/files rather than text.
Is this repository still being monitored ?
Are pull requests still welcome?
Yup, still monitored but not in development. PRs welcome!
You can send your messages with photo as text messages for testing purposes.
I have a simple solution for Telegraf Bot Framework.
const Telegraf = require('telegraf') const TelegrafContext = require('telegraf/context') class MyContext extends TelegrafContext { replyWithPhoto (photo, ...extra) { const { caption, ...rest } = extra[0] this.assert(this.chat, 'reply') const text = `[${photo}]\n${caption}` return this.telegram.sendMessage(this.chat.id, text, rest) } } const bot = new Telegraf("bot_token", { telegram: { apiRoot: server.ApiURL, }, contextType: MyContext, })
This is just for telegraf framework right? Not node-telegram-api
Yup, still monitored but not in development. PRs welcome!
Alright. Cool!
const text = `[${photo}]\n${caption}`
What is photo in this case?
You can send your messages with photo as text messages for testing purposes.
I have a simple solution for Telegraf Bot Framework.
const Telegraf = require('telegraf') const TelegrafContext = require('telegraf/context') class MyContext extends TelegrafContext { replyWithPhoto (photo, ...extra) { const { caption, ...rest } = extra[0] this.assert(this.chat, 'reply') const text = `[${photo}]\n${caption}` return this.telegram.sendMessage(this.chat.id, text, rest) } } const bot = new Telegraf("bot_token", { telegram: { apiRoot: server.ApiURL, }, contextType: MyContext, })
@aveeday Please kindly look at my questions
@aveeday Please kindly look at my questions
This patch is just for telegraf. Photo in my case is a string with url.
It is not necessary to run telegram server for testing locally. I think the best practices are just require bot in test file and call handle update method.
Yup, still monitored but not in development. PRs welcome!
I just got to know that you built another test library called telegram-test. Does that have the functionality of client being able to send images by any chance? Thanks
@aveeday Please kindly look at my questions
This patch is just for telegraf. Photo in my case is a string with url.
It is not necessary to run telegram server for testing locally. I think the best practices are just require bot in test file and call handle update method.
Thanks for the reply @aveeday . This library starts a server locally, are you saying that is not neccessary for testing locally? Sorry for the questions. Kind of new to this.
Also, can you pls point me to a sample test file/project you have written in the past?
Thanks
Telegram bot can send messages in two ways:
All this external communications can be mocked and bot answers can be checked in tests. I created a simple testing example to show the proof of this concept. This implementation can be easily extended for your specific needs and rewritten to any language, framework and libs you like. You can integrate this bot with Express or any other http framework/infrastructure with bot.handleUpdate()
or just use internal server with bot.launch()
@jehy After changes are being made to this library which changes some APIs, will a new version be released?
@tundeOlagunju yup, everything will happen according to semantic versioning model.
Is there a way to send a photo instead of text