Skip to content

Commit

Permalink
Merge pull request #6 from dialoguetoolkit/development
Browse files Browse the repository at this point in the history
updated to new Telegram Bot API version
  • Loading branch information
dialoguetoolkit authored Jan 6, 2022
2 parents 24cc299 + 671811f commit b12d113
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 113 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lx</groupId>
<artifactId>chattoolTG</artifactId>
<version>5.3.2</version>
<version>5.3.5</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.8.1</version>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
Expand Down
145 changes: 76 additions & 69 deletions src/main/java/diet/server/Conversation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import diet.tg.TelegramParticipant;
import diet.tg.tgSTARTER;
import java.awt.Color;
import static java.awt.SystemColor.text;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand All @@ -50,6 +49,7 @@
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageReplyMarkup;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.PhotoSize;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
Expand Down Expand Up @@ -2669,9 +2669,9 @@ public void deprecated_telegram_relayMessageTextToOtherParticipantsOLD(TelegramP
TelegramParticipant recipient = (TelegramParticipant)recipients.elementAt(i);
long recipientID = recipient.getConnection().telegramID;

SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID)
.setText(text);
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(text);
recipient.sendMessage(message);
System.err.println("HEREINCOMING102");

Expand Down Expand Up @@ -2714,9 +2714,9 @@ public void telegram_relayMessageTextToOtherParticipants(TelegramParticipant sen

long recipientID = recipient.getConnection().telegramID;

SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.disableNotification();
message.enableHtml(true);
message.setText("<b>"+sender.getUsername()+": </b>"+text);

Expand Down Expand Up @@ -2779,10 +2779,10 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendInstructi
long recipientID = recipient.getConnection().telegramID;

try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID)
.setText(markdown);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(markdown);
message.disableNotification();
message.enableMarkdown(true);

message.setText(markdown);
Expand Down Expand Up @@ -2834,10 +2834,10 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendInstructi
long recipientID = recipient.getConnection().telegramID;

try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID)
.setText(html);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(html);
message.disableNotification();
message.enableHtml(true);

message.setText(html);
Expand Down Expand Up @@ -2887,10 +2887,10 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendInstructi
long recipientID = recipient.getConnection().telegramID;

try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID)
.setText(text);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(text);
message.disableNotification();
message.enableHtml(true);

message.setText("<code>"+text+"</code>");
Expand Down Expand Up @@ -2941,10 +2941,10 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendInstructi
long recipientID = recipient.getConnection().telegramID;

try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID)
.setText(markdownv2);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(markdownv2);
message.disableNotification();
message.enableMarkdownV2(conversationIsActive);
message.setText("<code>"+markdownv2+"</code>");
org.telegram.telegrambots.meta.api.objects.Message m = recipient.sendMessage(message);
Expand Down Expand Up @@ -3029,9 +3029,10 @@ public void telegram_sendInstructionToParticipantWithForcedKeyboardButtons(Teleg
long recipientID = recipient.getConnection().telegramID;

try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID).setText(messageText);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(messageText);
message.disableNotification();
message.enableHtml(false);
//message.setText("<code>"+text+"</code>");

Expand Down Expand Up @@ -3097,10 +3098,10 @@ public void telegram_sendInstructionToParticipantWithForcedKeyboardButtons(Teleg
long recipientID = recipient.getConnection().telegramID;

try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID)
.setText(text);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(text);
message.disableNotification();
message.enableHtml(true);
message.setText("<code>"+text+"</code>");

Expand Down Expand Up @@ -3167,10 +3168,10 @@ public void telegram_sendURL(TelegramParticipant recipient, String text){
long recipientID = recipient.getConnection().telegramID;

try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID)
.setText(text);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.setText(text);
message.disableNotification();
message.enableHtml(true);
message.setText("<a href=\""+text+"\">"+text+ "</a>");
recipient.sendMessage(message);
Expand Down Expand Up @@ -3240,9 +3241,9 @@ private void telegram_sendArtificialTurnFromApparentOriginToParticipantID(String

long recipientID = recipient.getConnection().telegramID;

SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.disableNotification();
message.enableHtml(true);
message.setText("<b>"+apparentSenderString+": </b>"+text);
recipient.sendMessage(message);
Expand Down Expand Up @@ -3342,9 +3343,9 @@ private void telegram_sendArtificialTurnFromApparentOriginToParticipantID(Telegr

long recipientID = recipient.getConnection().telegramID;

SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(recipientID);
message = message.disableNotification();
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(""+recipientID);
message.disableNotification();
message.enableHtml(true);
message.setText("<b>"+apparentSender.getUsername()+": </b>"+text);
recipient.sendMessage(message);
Expand Down Expand Up @@ -3401,10 +3402,10 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendPhoto_By_
long recipientID = recipient.getConnection().telegramID;

try{
SendPhoto msg = new SendPhoto()
.setChatId(recipientID)
.setPhoto(file_id);
msg = msg.disableNotification();
SendPhoto msg = new SendPhoto();
msg.setChatId(""+recipientID);
msg.setPhoto(new InputFile(file_id));
msg.disableNotification();

try{
String group =cC.pp.getSubdialogueID(recipient);
Expand Down Expand Up @@ -3467,10 +3468,10 @@ public void telegram_relayMessagePhotoToOtherParticipants_By_File_ID(TelegramPar
TelegramParticipant recipient = (TelegramParticipant)recipients.elementAt(i);
vRecipientsUsernames.add(recipient.getUsername());
long recipientID = recipient.getConnection().telegramID;
SendPhoto msg = new SendPhoto()
.setChatId(recipientID)
.setPhoto(file_id);
msg = msg.disableNotification();
SendPhoto msg = new SendPhoto();
msg.setChatId(""+recipientID);
msg.setPhoto(new InputFile(file_id));
msg.disableNotification();



Expand Down Expand Up @@ -3562,7 +3563,9 @@ public void telegram_relayMessageVoiceToOtherParticipants_By_File_ID(TelegramPar
msg = msg.disableNotification();
*/

SendVoice msg = new SendVoice().setChatId(recipientID).setVoice(fileid);
SendVoice msg = new SendVoice();
msg.setChatId(""+recipientID);
msg.setVoice(new InputFile(fileid));


recipient.sendVoice(msg);
Expand Down Expand Up @@ -3655,10 +3658,11 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendPhoto_By_

try{

SendPhoto msg = new SendPhoto()
.setChatId(recipientID)
.setCaption("").setPhoto(f);
msg = msg.disableNotification();
SendPhoto msg = new SendPhoto();
msg.setChatId(""+recipientID);
msg.setCaption("");
msg.setPhoto(new InputFile(f));
msg.disableNotification();



Expand All @@ -3684,7 +3688,7 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendPhoto_By_

InlineKeyboardMarkup im = new InlineKeyboardMarkup();
im.setKeyboard(keybb);
msg = msg.setReplyMarkup(im);
msg.setReplyMarkup(im);

}

Expand Down Expand Up @@ -3734,7 +3738,9 @@ public void telegram_DeleteMessage_DoNotCallThisMethodDirectlyFromController(Tel


try{
DeleteMessage dm = new DeleteMessage().setChatId(recipientID).setMessageId(message_id);
DeleteMessage dm = new DeleteMessage();
dm.setChatId(""+recipientID);
dm.setMessageId(message_id);
System.err.println("CREATING DELETEMESSAGE: "+recipientID+" "+message_id);

String group =cC.pp.getSubdialogueID(recipient);
Expand Down Expand Up @@ -3804,7 +3810,7 @@ public void telegram_sendEditMessageToParticipant(TelegramParticipant recipient,

emt.enableHtml(true);
emt.setText("<code>"+replacementText+"</code>");
emt.setChatId(messagechatid);
emt.setChatId(""+messagechatid);
emt.setMessageId(messageID);

recipient.sendEditMessage(mOriginalMessage, emt);
Expand Down Expand Up @@ -3857,8 +3863,8 @@ public void telegram_sendPinChatMessageToParticipant(TelegramParticipant recipie
try{

PinChatMessage pcm = new PinChatMessage() ;
pcm = pcm.setMessageId(messageToBePinned.getMessageId());
pcm = pcm.setChatId(messageToBePinned.getChatId());
pcm.setMessageId(messageToBePinned.getMessageId());
pcm.setChatId(""+messageToBePinned.getChatId());

String group =cC.pp.getSubdialogueID(recipient);

Expand Down Expand Up @@ -3935,8 +3941,8 @@ public void telegram_sendEditMessageReplyMarkup(TelegramParticipant recipient, I
try{

EditMessageReplyMarkup emrm = new EditMessageReplyMarkup();
if(inlineMessageID!=null)emrm = emrm.setInlineMessageId(inlineMessageID);
if(messagechatid!=null)emrm = emrm.setChatId(messagechatid);
if(inlineMessageID!=null) emrm.setInlineMessageId(inlineMessageID);
if(messagechatid!=null)emrm.setChatId(""+messagechatid);
emrm.setMessageId(messageID);


Expand All @@ -3963,12 +3969,12 @@ public void telegram_sendEditMessageReplyMarkup(TelegramParticipant recipient, I

InlineKeyboardMarkup im = new InlineKeyboardMarkup();
im.setKeyboard(keybb);
emrm = emrm.setReplyMarkup(im);
emrm.setReplyMarkup(im);

}
else{
InlineKeyboardMarkup im = new InlineKeyboardMarkup();
emrm = emrm.setReplyMarkup(im);
emrm.setReplyMarkup(im);
}


Expand Down Expand Up @@ -4032,16 +4038,17 @@ public org.telegram.telegrambots.meta.api.objects.Message telegram_sendPoll(Tele

try{
SendPoll sp = new SendPoll();
sp = sp.setQuestion(question);
sp = sp.setOptions( Arrays.asList(options));
sp = sp.setExplanation(explanation);
sp = sp.setAnonymous(true);
sp =sp.setAllowMultipleAnswers(allowMultipleSelections);
sp.setQuestion(question);
sp.setOptions( Arrays.asList(options));
sp.setExplanation(explanation);

sp.setIsAnonymous(true);
sp.setAllowMultipleAnswers(allowMultipleSelections);



sp=sp.setChatId(recipientID);
sp=sp.disableNotification();
sp.setChatId(""+recipientID);
sp.disableNotification();


try{
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/diet/tg/IDCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public boolean processTelegramMessage(Update update){
public boolean processTelegramCallback(Update update){
TelegramParticipantConnection telegramparticipconnection= null;

int id = update.getCallbackQuery().getFrom().getId();
long id = update.getCallbackQuery().getFrom().getId();

telegramparticipconnection= this.idcIO.getLogFile(id);
if(telegramparticipconnection ==null){
Expand Down Expand Up @@ -276,7 +276,7 @@ public boolean processTelegramCallback(Update update){
public boolean processTelegramPollAnswer(Update update){
TelegramParticipantConnection telegramparticipconnection= null;

int id = update.getCallbackQuery().getFrom().getId();
long id = update.getCallbackQuery().getFrom().getId();

telegramparticipconnection= this.idcIO.getLogFile(id);
if(telegramparticipconnection ==null){
Expand Down Expand Up @@ -353,9 +353,9 @@ public boolean processTelegramPollAnswer(Update update){

public void sendMessageAndSaveToLog(long telegramID, String msg){
try{
SendMessage message = new SendMessage() // Create a SendMessage object with mandatory fields
.setChatId(telegramID)
.setText(msg);
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message .setChatId(""+telegramID);
message.setText(msg);
this.cttgbot.sendMessage(message);

TelegramParticipantConnection telegramIDRecord= this.idcIO.getLogFile(telegramID);
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/diet/tg/TGASYNCMEDIAGETTER.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,14 @@ private PhotoSize getPhoto(Update update) {

private String getFilePath(PhotoSize photo) {
Objects.requireNonNull(photo);

if (photo.hasFilePath()) { // If the file_path is already present, we are done!
System.err.println("PHOT:IT HAS A FILE PATH: "+photo.getFilePath().toString());

try{
return photo.getFilePath();
} else { // If not, let find it
}catch (Exception e){
e.printStackTrace();
}

//If not, let find it
// We create a GetFile method and set the file_id from the photo
System.err.println("PHOT:IT DOESN'T HAVE A FILE PATH: ");
GetFile getFileMethod = new GetFile();
Expand All @@ -225,7 +228,7 @@ private String getFilePath(PhotoSize photo) {
} catch (TelegramApiException e) {
e.printStackTrace();
}
}


return null; // Just in case
}
Expand Down
Loading

0 comments on commit b12d113

Please sign in to comment.