B4J Question how sendmessage to telegram group via jtelegrambot

behnam_tr

Active Member
Licensed User
how can i sendmessage or deletmessage to telegram group via jtelegrambot

i use this code and got error
my bot is a admin in the group
i can get the message but i cant send to group

B4X:
jtb.sendMessage(jtb.byId(from.Id),"welcome to the group","MARKDOWN",False,True,Null,Null)

jtb.DeleteMessage( jtb.byId(from.Id), id)
 

DonManfred

Expert
Licensed User
i use this code and got error
I don´t see any full error in your post.
Saying it raises and error but hiding the error is the wrong way to get help.

Start with declaring which library you are using. There are multiple telegrambot libs.
 
Upvote 0

behnam_tr

Active Member
Licensed User
send message solved with this code
B4X:
jtb.sendMessage(jtb.byId(chat.Id),"kkkkkkkkkk","MARKDOWN",True,False,Null,Null)

deletemessage method can delete message from group with this code but i get error

B4X:
jtb.DeleteMessage(jtb.byId(chat.Id),message.MessageId)

error

B4X:
Waiting for debugger to connect...
Program started.
JTelegramBot (goldstar_pd_bot) starts in "Polling" mode.
JTB_onMessageReceived( 344457956, Message{messageId=49, from=User{id=105526931, firstName='Padina System', lastName='null', username='padina_system'}, date=1564130205, chat=Chat{id=-368358078, type=group, title='اتاق تست معاملات', username='null', firstName='null', lastName='null'}, forwardFrom=null, forwardFromChat=null, forwardDate=null, replyToMessage=null, editDate=0, text='هما', entities=null, audio=null, document=null, photo=null, sticker=null, video=null, voice=null, caption='null', contact=null, location=null, venue=null, newChatMember=null, leftChatMember=null, newChatTitle='null', newChatPhoto=null, deleteChatPhoto=null, groupChatCreated=null, superGroupChatCreated=null, channelChatCreated=null, migrateToChatId=null, migrateFromChatId=null, pinnedMessage=null}
Error occurred on line: 92 (Main)
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `io.fouad.jtb.core.beans.User` (although at least one Creator exists): no boolean/Boolean-argument constructor/factory method to deserialize from boolean value (true)
 at [Source: (String)"{"ok":true,"result":true}
"; line: 1, column: 21] (through reference chain: io.fouad.jtb.core.beans.TelegramResult["result"])
    at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
    at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1343)
    at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1032)
    at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromBoolean(ValueInstantiator.java:280)
    at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromBoolean(StdValueInstantiator.java:393)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromBoolean(BeanDeserializerBase.java:1426)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:180)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161)
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3023)
    at io.fouad.jtb.core.utils.JsonUtils.toJavaObject(JsonUtils.java:51)
    at io.fouad.jtb.core.JTelegramBot.DeleteMessage(JTelegramBot.java:987)
    at de.donmanfred.JTBwrapper.DeleteMessage(JTBwrapper.java:265)
    at b4j.example.main._jtb_onmessagereceived(main.java:182)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$3.run(BA.java:247)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:29)
 
Last edited:
Upvote 0

behnam_tr

Active Member
Licensed User
also i get this error when i want to editmessage

B4X:
jtb.editMessageText(jtb.byId(chat.Id),kk.MessageId,""," admin edit your message","MARKDOWN",True,Null)


B4X:
Waiting for debugger to connect...
Program started.
JTelegramBot (goldstar_pd_bot) starts in "Polling" mode.
JTB_onMessageReceived( 344457961, Message{messageId=57, from=User{id=105526931, firstName='Padina System', lastName='null', username='padina_system'}, date=1564130824, chat=Chat{id=-368358078, type=group, title='اتاق تست معاملات', username='null', firstName='null', lastName='null'}, forwardFrom=null, forwardFromChat=null, forwardDate=null, replyToMessage=null, editDate=0, text='سلام', entities=null, audio=null, document=null, photo=null, sticker=null, video=null, voice=null, caption='null', contact=null, location=null, venue=null, newChatMember=null, leftChatMember=null, newChatTitle='null', newChatPhoto=null, deleteChatPhoto=null, groupChatCreated=null, superGroupChatCreated=null, channelChatCreated=null, migrateToChatId=null, migrateFromChatId=null, pinnedMessage=null}
msgid==58
Error occurred on line: 98 (Main)
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
 at [Source: (String)"{"ok":true,"result":{"message_id":58,"from":{"id":943334940,"is_bot":true,"first_name":"GoldStar_admin","username":"goldstar_pd_bot"},"chat":{"id":-368358078,"title":"\u0627\u062a\u0627\u0642 \u062a\u0633\u062a \u0645\u0639\u0627\u0645\u0644\u0627\u062a","type":"group","all_members_are_administrators":false},"date":1564130825,"edit_date":1564130833,"text":"\u0633\u0644\u0627\u0645(\u0645\u0646\u0642\u0636\u06cc \u0634\u062f)"}}
"; line: 1, column: 21] (through reference chain: io.fouad.jtb.core.beans.TelegramResult["result"])
    at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
    at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1343)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1139)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1093)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:63)
    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:10)
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3023)
    at io.fouad.jtb.core.utils.JsonUtils.toJavaObject(JsonUtils.java:51)
    at io.fouad.jtb.core.JTelegramBot.editMessageText(JTelegramBot.java:884)
    at de.donmanfred.JTBwrapper.editMessageText(JTBwrapper.java:736)
    at b4j.example.main$ResumableSub_JTB_onMessageReceived.resume(main.java:223)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
    at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1018)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:29)
 
Upvote 0

DonManfred

Expert
Licensed User
1. You did not defined which library you are using exactly. AGAIN: there are more than one and i just want to make sure you are using my wrapper or not.
As long i did not know this i´ll not answer anymore.
2. You should ALWAYS create a NEW thread for any NEW issue. Do not expect me to answer to another problem in the same thread.
 
Upvote 0
Top