mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-21 21:33:12 +01:00
Added ability to send files. Useful for future send calendar event implementation
This commit is contained in:
@@ -40,6 +40,9 @@ class Bot(telegram: TelegramBot /* other bots */) extends Logger {
|
|||||||
def sendEditMessage(source: MessageSource, messageId: String, text: String, inlineKeyboard: Option[InlineKeyboard] = None): Unit =
|
def sendEditMessage(source: MessageSource, messageId: String, text: String, inlineKeyboard: Option[InlineKeyboard] = None): Unit =
|
||||||
resolveAdapter(source).sendEditMessage(source.chatId, messageId, text, inlineKeyboard)
|
resolveAdapter(source).sendEditMessage(source.chatId, messageId, text, inlineKeyboard)
|
||||||
|
|
||||||
|
def sendFile(source: MessageSource, filename: String, contents: Array[Byte], caption: Option[String] = None): Unit =
|
||||||
|
resolveAdapter(source).sendFile(source.chatId, filename, contents, caption)
|
||||||
|
|
||||||
private def resolveAdapter(source: MessageSource): PollBot[_] =
|
private def resolveAdapter(source: MessageSource): PollBot[_] =
|
||||||
source.sourceSystem match {
|
source.sourceSystem match {
|
||||||
case TelegramMessageSourceSystem => telegram
|
case TelegramMessageSourceSystem => telegram
|
||||||
|
|||||||
@@ -34,5 +34,7 @@ trait PollBot[In <: Event] {
|
|||||||
|
|
||||||
def sendEditMessage(chatId: String, messageId: String, text: String, buttons: Option[InlineKeyboard] = None): Unit
|
def sendEditMessage(chatId: String, messageId: String, text: String, buttons: Option[InlineKeyboard] = None): Unit
|
||||||
|
|
||||||
|
def sendFile(chatId: String, filename: String, contents: Array[Byte], caption: Option[String] = None): Unit
|
||||||
|
|
||||||
protected def onReceive(command: In): Unit
|
protected def onReceive(command: In): Unit
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ class TelegramBot(onCommand: Command => Unit, botToken: String) extends PollBot[
|
|||||||
def sendEditMessage(chatId: String, messageId: String, text: String, buttons: Option[InlineKeyboard] = None): Unit =
|
def sendEditMessage(chatId: String, messageId: String, text: String, buttons: Option[InlineKeyboard] = None): Unit =
|
||||||
telegramBot.sendEditMessage(chatId.toLong, messageId.toInt, text, replyMarkup = buttons.map(_.mapTo[InlineKeyboardMarkup]))
|
telegramBot.sendEditMessage(chatId.toLong, messageId.toInt, text, replyMarkup = buttons.map(_.mapTo[InlineKeyboardMarkup]))
|
||||||
|
|
||||||
|
def sendFile(chatId: String, filename: String, contents: Array[Byte], caption: Option[String] = None): Unit =
|
||||||
|
telegramBot.sendFile(chatId.toLong, filename, contents, caption)
|
||||||
|
|
||||||
override protected def onReceive(command: TelegramEvent): Unit = {
|
override protected def onReceive(command: TelegramEvent): Unit = {
|
||||||
onCommand(command.mapTo[Command])
|
onCommand(command.mapTo[Command])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ package com.lbs.bot.telegram
|
|||||||
import com.lbs.common.Logger
|
import com.lbs.common.Logger
|
||||||
import info.mukel.telegrambot4s.api.declarative.{Callbacks, Commands}
|
import info.mukel.telegrambot4s.api.declarative.{Callbacks, Commands}
|
||||||
import info.mukel.telegrambot4s.api.{Polling, TelegramBot => TelegramBotBase}
|
import info.mukel.telegrambot4s.api.{Polling, TelegramBot => TelegramBotBase}
|
||||||
import info.mukel.telegrambot4s.methods.{EditMessageReplyMarkup, EditMessageText, ParseMode, SendMessage}
|
import info.mukel.telegrambot4s.methods._
|
||||||
import info.mukel.telegrambot4s.models._
|
import info.mukel.telegrambot4s.models._
|
||||||
|
|
||||||
import scala.concurrent.Future
|
import scala.concurrent.Future
|
||||||
@@ -47,6 +47,9 @@ class TelegramClient(onReceive: TelegramEvent => Unit, botToken: String) extends
|
|||||||
def sendEditMessage(chatId: Long, messageId: Int, text: String, replyMarkup: Option[InlineKeyboardMarkup] = None): Future[Either[Boolean, Message]] =
|
def sendEditMessage(chatId: Long, messageId: Int, text: String, replyMarkup: Option[InlineKeyboardMarkup] = None): Future[Either[Boolean, Message]] =
|
||||||
request(EditMessageText(Some(chatId), Some(messageId), text = text, parseMode = Some(ParseMode.HTML), replyMarkup = replyMarkup))
|
request(EditMessageText(Some(chatId), Some(messageId), text = text, parseMode = Some(ParseMode.HTML), replyMarkup = replyMarkup))
|
||||||
|
|
||||||
|
def sendFile(chatId: Long, filename: String, contents: Array[Byte], caption: Option[String] = None): Future[Message] =
|
||||||
|
request(SendDocument(chatId, InputFile(filename, contents), caption))
|
||||||
|
|
||||||
|
|
||||||
override def receiveMessage(msg: Message): Unit = {
|
override def receiveMessage(msg: Message): Unit = {
|
||||||
debug(s"Received telegram message: $msg")
|
debug(s"Received telegram message: $msg")
|
||||||
|
|||||||
Reference in New Issue
Block a user