Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send photo instead of text #30

Open
AnthonyMouallem opened this issue Jan 3, 2020 · 16 comments
Open

send photo instead of text #30

AnthonyMouallem opened this issue Jan 3, 2020 · 16 comments

Comments

@AnthonyMouallem
Copy link

Is there a way to send a photo instead of text

@aveeday
Copy link

aveeday commented Jan 7, 2020

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,
})

@b3nab
Copy link

b3nab commented Feb 25, 2020

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?

@tundeOlagunju
Copy link

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.

@tundeOlagunju
Copy link

Is this repository still being monitored ?

@tundeOlagunju
Copy link

Are pull requests still welcome?

@jehy
Copy link
Owner

jehy commented Sep 29, 2020

Yup, still monitored but not in development. PRs welcome!

@tundeOlagunju
Copy link

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

@tundeOlagunju
Copy link

Yup, still monitored but not in development. PRs welcome!

Alright. Cool!

@tundeOlagunju
Copy link

const text = `[${photo}]\n${caption}`

What is photo in this case?

@tundeOlagunju
Copy link

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
Copy link

aveeday commented Sep 29, 2020

@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.

@tundeOlagunju
Copy link

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

@tundeOlagunju
Copy link

@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

@aveeday
Copy link

aveeday commented Oct 2, 2020

Telegram bot can send messages in two ways:

  1. call telegram api
  2. send response to web hook

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()

https://github.com/aveeday/telegraf-testing-example

@tundeOlagunju
Copy link

@jehy After changes are being made to this library which changes some APIs, will a new version be released?

@jehy
Copy link
Owner

jehy commented Nov 12, 2020

@tundeOlagunju yup, everything will happen according to semantic versioning model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants