Page 6 of 7

Re: PureTelegram (framework for using the Telegram API)

Posted: Thu Jan 05, 2023 12:55 pm
by Caronte3D
The program stoped here (I think is because the caption is te same already on the msg):

Image

Re: PureTelegram (framework for using the Telegram API)

Posted: Thu Jan 05, 2023 3:04 pm
by Seymour Clufley
What does MemorySize(*SourceBuffer) tell you?

Re: PureTelegram (framework for using the Telegram API)

Posted: Thu Jan 05, 2023 5:34 pm
by Caronte3D
Seymour Clufley wrote: Thu Jan 05, 2023 3:04 pm What does MemorySize(*SourceBuffer) tell you?
Image

Re: PureTelegram (framework for using the Telegram API)

Posted: Thu Jan 05, 2023 6:04 pm
by Caronte3D
I don't know if that's ok :?
Image

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Jan 06, 2023 6:52 am
by Seymour Clufley
I just tried this code, and it works perfectly - whether the captions are identical or not, and whether the MessageRequester() line is there or not.

Code: Select all

img1.i = CreateImage(#PB_Any,300,200,24,RGB(255,0,0))
img2.i = CreateImage(#PB_Any,300,200,24,RGB(0,255,0))
lastMsgID = Telegram_PostPBImage(#BotAPIToken,#ChatID,img1,"caption")
MessageRequester("Info","Pause before changing the image.")
If Not Telegram_ReplaceMessageImageWithPBImage(#BotAPIToken,#ChatID,lastMsgID,img2,"caption")
  ultimoMsgID = Telegram_PostPBImage(#BotAPIToken,#ChatID,img2,"caption")
EndIf
I wonder if your error is happening because of memory allocation. Try this new version of the MPFR_Create() procedure and see if the code works:

Code: Select all

Procedure.i MPFR_Create()
  reqs = ArraySize(MPFRequest())
  For q = 1 To reqs
    If Not MPFRequest(q)\active
      MPFRequest(q)\active = #True
      ProcedureReturn q
    EndIf
  Next q
  
  reqs+1
  If reqs>ArraySize(MPFRequest())
    ReDim MPFRequest(reqs)
  EndIf
  MPFRequest(reqs)\active = #True
  ProcedureReturn reqs
  
EndProcedure
If that doesn't work, try replacing the MPFR_Free() procedure with this:

Code: Select all

Procedure.b MPFR_Free(q.i)
  With MPFRequest(q)
    ForEach \field()
      If \field()\SourceBuffer<>0
        FreeMemory(\field()\SourceBuffer)
      EndIf
    Next
    ClearList(\field())
    \active = #False
  EndWith
EndProcedure
If that doesn't work, keep this new version of MPFR_Free() and uncomment the line "ProcedureReturn q" in the MPFR_Create() procedure, and try again.

Let me know if any of this works.

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Jan 06, 2023 10:43 am
by Caronte3D
None of these solutions works :( I get the same error at the same line:
[10:35:14] [ERROR] Invalid memory access. (write error at address 141822908)

For your information, the error does not occurs the first time, some times at the second time, sometimes 3º, 4º... but everytime fails at some point with the same error on the same line.

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Jan 06, 2023 12:56 pm
by Seymour Clufley
Try changing the MPFR_Create() procedure to this:

Code: Select all

Procedure.i MPFR_Create()
  reqs = ArraySize(MPFRequest())
  For q = 1 To reqs
    If Not MPFRequest(q)\active
      InitializeStructure(@MPFRequest(q),MPFRequestStructure)
      MPFRequest(q)\active = #True
      ProcedureReturn q
    EndIf
  Next q
  
  reqs+1
  If reqs>ArraySize(MPFRequest())
    ReDim MPFRequest(reqs)
  EndIf
  InitializeStructure(@MPFRequest(reqs),MPFRequestStructure)
  MPFRequest(reqs)\active = #True
  ProcedureReturn reqs
  
EndProcedure

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Jan 06, 2023 8:21 pm
by Caronte3D
Your last code doesn´t work either, but I think I found the bug.

If I activate the Purifier y get this error:

[20:04:10] [ERROR] MultipartFormDataRequests.pbi (Linea: 171)
[20:04:10] [ERROR] Overflow in a dynamically allocated memory block.

I added the "+1" to this line:
\SourceBuffer = AllocateMemory(\DataLen+1)

Maybe to add extrasize for the null terminator?

Please check it in case I was wrong, but that solved my problem :D

Code: Select all

Procedure.b MPFR_AddJSON(q.i,field_name.s,js.i)
  AddElement(MPFRequest(q)\field())
  With MPFRequest(q)\field()
    \field_type = #MPFR_FieldType_Data
    \mime = MimeType("json")
    \field_parameter("name") = field_name
    t.s = ComposeJSON(js)
    \DataLen = StringByteLength(t,#PB_UTF8)
    \SourceBuffer = AllocateMemory(\DataLen+1)
    PokeS(\SourceBuffer,t,-1,#PB_UTF8)
  EndWith
EndProcedure

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Jan 07, 2023 8:19 am
by Seymour Clufley
Right, thank you. Did you use the MPFR_AddJSON procedure in your code?

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Jan 07, 2023 8:56 am
by Caronte3D
Seymour Clufley wrote: Sat Jan 07, 2023 8:19 am Right, thank you. Did you use the MPFR_AddJSON procedure in your code?
No, on my code I only use these five procedures:
Telegram_PostPBImage
Telegram_DeleteMessage
Telegram_EditMessageCaption
Telegram_ReplaceMessageImageWithPBImage
Telegram_PinMessage

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Jan 07, 2023 9:53 am
by Seymour Clufley
But making this change to the JSON procedure has fixed the bug...?

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Jan 07, 2023 10:08 am
by Caronte3D
Seymour Clufley wrote: Sat Jan 07, 2023 9:53 am But making this change to the JSON procedure has fixed the bug...?
Yes, 100% tested.
Some of your procedures are using it indirectly (maybe)

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Jan 07, 2023 2:06 pm
by Seymour Clufley
Oh, I see now. I use it in some of the procedures.

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Jan 07, 2023 6:56 pm
by Caronte3D
When you fix the bug, please edit the first post with the corrected code.
Also... the initNetwork() is deprecated now :wink:

Re: PureTelegram (framework for using the Telegram API)

Posted: Wed Jun 25, 2025 10:30 am
by dibor
Hello.
First, tnx for the module.
Any update of this module?
I got error of initNetwork() :(
[12:29:43] [COMPILER] Line 27: InitNetwork() is not a function, array, list, map or macro.
And sure, nothing work :(

Checked with PB 6.21 x64

Thank U