B4J Question doubts in jtelegram Lib

thader2012

Member
Licensed User
Hello @DonManfred

I'm now doing little things on telegram with your library. I have a question about it. There is an object in the onInlineQueryReceived event to capture the query object?, I think it is of the inlinequey type but I can't find it, and also some object of the inlinequeryresultcachedphoto type to respond to an online bot.

Thank you for your library and for all your contributions.

a greeting
 

DonManfred

Expert
Licensed User
The wrapper is incomplete. I just did it just for fun
I stopped development time ago. I uploaded the source if i remember correctly.
Feel free to further delop it.
 
Last edited:
Upvote 0

thader2012

Member
Licensed User
Hello @DonManfred

I have started to wrap some classes like the inlineQuery and it has worked. I have to confess that I am not an expert in Java, I have noticed your work in others and it has come out. Thanks for your work.

I have continued with the InlinequeryResult worse I have had a problem tells me.

B4X:
InlineQueryResult is abstract; cannot be instantiated
        this.setObject(new InlineQueryResult());
                       ^
1 error

The file is
Java:
package io.fouad.jtb.core.beans;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* This object represents one result of an inline query.
* Telegram clients currently support results of the following 19 types:
*
* - InlineQueryResultCachedAudio
* - InlineQueryResultCachedDocument
* - InlineQueryResultCachedGif
* - InlineQueryResultCachedMpeg4Gif
* - InlineQueryResultCachedPhoto
* - InlineQueryResultCachedSticker
* - InlineQueryResultCachedVideo
* - InlineQueryResultCachedVoice
* - InlineQueryResultArticle
* - InlineQueryResultPhoto
* - InlineQueryResultContact
* - InlineQueryResultDocument
* - InlineQueryResultGif
* - InlineQueryResultLocation
* - InlineQueryResultMpeg4Gif
* - InlineQueryResultPhoto
* - InlineQueryResultVenue
* - InlineQueryResultVideo
* - InlineQueryResultVoice
* - InlineQueryResultArticle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class InlineQueryResult
{
    /**
     * Type of the result.
     */
    @JsonProperty("type")
    private String type;
   
    /**
     * Unique identifier for this result, 1-64 bytes.
     */
    @JsonProperty("id")
    private String id;
   
    /**
     * Optional. Inline keyboard attached to the message.
     */
    @JsonProperty("reply_markup")
    private InlineKeyboardMarkup replyMarkup;
   
    public InlineQueryResult(){}
   
    public InlineQueryResult(String type, String id, InlineKeyboardMarkup replyMarkup)
    {
        this.type = type;
        this.id = id;
        this.replyMarkup = replyMarkup;
    }
   
    public String getType(){return type;}
    public void setType(String type){this.type = type;}
   
    public String getId(){return id;}
    public void setId(String id){this.id = id;}
   
    public InlineKeyboardMarkup getReplyMarkup(){return replyMarkup;}
    public void setReplyMarkup(InlineKeyboardMarkup replyMarkup){this.replyMarkup = replyMarkup;}
   
    @Override
    public boolean equals(Object o)
    {
        if(this == o) return true;
        if(!(o instanceof InlineQueryResult)) return false;
       
        InlineQueryResult that = (InlineQueryResult) o;
       
        if(type != null ? !type.equals(that.type) : that.type != null) return false;
        if(id != null ? !id.equals(that.id) : that.id != null) return false;
        return replyMarkup != null ? replyMarkup.equals(that.replyMarkup) : that.replyMarkup == null;
       
    }
   
    @Override
    public int hashCode()
    {
        int result = type != null ? type.hashCode() : 0;
        result = 31 * result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (replyMarkup != null ? replyMarkup.hashCode() : 0);
        return result;
    }
   
    @Override
    public String toString()
    {
        return "InlineQueryResult{" +
                "type='" + type + '\'' +
                ", id='" + id + '\'' +
                ", replyMarkup=" + replyMarkup +
                '}';
    }
}

And the wrapper that I have made
Java:
package de.donmanfred;

import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
import io.fouad.jtb.core.beans.InlineKeyboardMarkup;
import io.fouad.jtb.core.beans.InlineQueryResult;


@ShortName("InlineQueryResult")
public class InlineQueryResultwrapper extends AbsObjectWrapper<InlineQueryResult> {
    private BA ba;
    private String eventName;
   
    private void InlineQueryResultwrapper(InlineQueryResult query){
        this.setObject(query);
    }
   
    //public void Initialize(BA ba, String EventName) {
    //    this.eventName = EventName.toLowerCase(BA.cul);
    //    this.ba = ba;
    //    this.setObject(new InlineQueryResult());
    //}
    public InlineQueryResult Initialize(){
        this.setObject(new InlineQueryResult());
        return this;
    }

    public String getType(){
        return getObject().getType();
    }
    // Obtener el texto de la consulta
    public String getId(){
        return getObject().getId();
    }
    public InlineKeyboardMarkup getReplyMarkup(){
        return getObject().getReplyMarkup();
    }
    public void setType( String Tipo){
        return getObject().setType(Tipo);
    }
    public void setId( String Id){
        return getObject().setType(Id);
    }
    public void setReplyMarkup( InlineKeyboardMarkup teclado){
        return getObject().setReplyMarkup(teclado);
    }


}


I'm sorry to ask you but I'm a little lost, could you give me a clue to get out of this error?

Thanks in advance

regards
 
Upvote 0

MathiasM

Active Member
Licensed User
I have never used the Telegram Lib.
But you're instantiating an Abstract Class with the New keyword. This is impossible.

That's like you would create a Code Module in B4J and do NewModule.Initialize

My main question when I see your code: Why is InlineQueryResult an abstract class?
 
Upvote 0

thader2012

Member
Licensed User
I think it uses the abstract class because there are 14 classes that are created from it and that way the results of an inline telegram query are sent in the same way.

The question is: Looking at the abstract class, how would the wrapper be done correctly?

I have removed the line from the setObject and it generates the library but when sending the results it tells me that it cannot cast InlineResultquery with InlinerResultquerywrapper.

Any suggestion.

Thanks for your help.

Greetings
B4X:
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
import io.fouad.jtb.core.beans.InlineKeyboardMarkup;
import io.fouad.jtb.core.beans.InlineQueryResult;

@ShortName("InlineQueryResult")
public class InlineQueryResultwrapper extends AbsObjectWrapper<InlineQueryResult> {
    private BA ba;
    private String eventName;
   
    public void InlineQueryResultwrapper(InlineQueryResult query){
        this.setObject(query);
    }
    public void Initialize(BA ba, String EventName) {
    this.eventName = EventName.toLowerCase(BA.cul);
    this.ba = ba;
       
    }
    //public void Initialize(BA ba, String EventName) {
    //  this.eventName = EventName.toLowerCase(BA.cul);
    //  this.ba = ba;
    //  this.setObject(new InlineQueryResult());
    //}
    //public InlineQueryResult Initialize(){
    //  this.setObject(new InlineQueryResult());
    //  return this;
    //}
   
    public String getType(){
        return getObject().getType();
    }
    // Obtener el texto de la consulta
    public String getId(){
        return getObject().getId();
    }
    public InlineKeyboardMarkup getReplyMarkup(){
        return getObject().getReplyMarkup();
    }
    public void setType( String Tipo){
         getObject().setType(Tipo);
    }
    public void setId( String Id){
        getObject().setType(Id);
    }
    public void setReplyMarkup( InlineKeyboardMarkup teclado){
        getObject().setReplyMarkup(teclado);
    }

}
 
Last edited:
Upvote 0
Top