Telegram File Compression uitschakelen?

Pagina: 1
Acties:

Vraag


Acties:
  • 0 Henk 'm!

  • PaulNellen
  • Registratie: Juli 2012
  • Laatst online: 23-05-2024
Beste Tweakers,

Sinds begin maart hebben ik en mjin collega's het probleem dat wanneer we een bestand verzenden in Telegram de upload naar onze server (windows) de upload wel goed gaat maar de kwaliteit zo slecht is dat de foto nauwelijks leesbaar is. De optie op een bestand te verzenden zonder file compression is er schijnbaar niet meer? Ik weet even niet meer waar ik het zoeken moet aangezien ik niets heb veranderd:

Mis ik iets? Onderstaand het script dat ik gebruik (althans het stuk waarvan ik denk dat het relevant is in deze)
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
function GetFileID(httpResponse)
'   get file_id from array of json telegram messages.
'   
    'skip first file_id from thumb
    TempStr=Right(httpResponse,Len(httpResponse)-InStr(httpResponse,"file_id")-6)
    'get second file_id
    TempStr=Right(TempStr,Len(TempStr)-InStr(TempStr,"file_id")-6)
    
    TempStr=Left(TempStr,InStr(TempStr,",")-2)
    
    Do While InStr(TempStr,"""") > 0
        TempStr=Right(TempStr, Len(TempStr)-InStr(TempStr,""""))
    Loop

    
    GetFileID=TempStr
End Function

Function GetFileName(httpResponse)
'   get file_name from array of json telegram messages.
'   
    
    TempStr=Right(httpResponse,Len(httpResponse)-InStr(httpResponse,"file_name")-6)
    
    TempStr=Left(TempStr,InStr(TempStr,",")-2)
    
    Do While InStr(TempStr,"""") > 0
        TempStr=Right(TempStr, Len(TempStr)-InStr(TempStr,""""))
    Loop

    
    GetFileName=TempStr
End Function

Function GetDownloadPath(StrFileID)
    sTempUrl = "https://api.telegram.org/bot" & sAPI_ID & "/getFile"
    sTempRequest = "file_id=" & StrFileID

        sTempResponse = HTTPPost(sTempUrl, sTempRequest)
    'get downloadpath
    
    sTempResponse=Right(sTempResponse,Len(sTempResponse)-InStr(sTempResponse,"file_path")-11)
    sTempResponse=Left(sTempResponse,InStr(sTempResponse,"""")-1)
    
    GetDownloadPath = sTempResponse
End Function

Function HTTPDownload( sURL, sPath )
    ' Fetch the file
    Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")

    objXMLHTTP.open "GET", sURL, false
    objXMLHTTP.send()

    If objXMLHTTP.Status = 200 Then
        Set objADOStream = CreateObject("ADODB.Stream")
        objADOStream.Open
        objADOStream.Type = 1 'adTypeBinary

        objADOStream.Write objXMLHTTP.ResponseBody
        objADOStream.Position = 0    'Set the stream position to the start

        Set objFSO = Createobject("Scripting.FileSystemObject")
        On Error Resume Next
        If objFSO.Fileexists(sPath) Then 
            objFSO.DeleteFile sPath
        End If
        Set objFSO = Nothing

        objADOStream.SaveToFile sPath
        objADOStream.Close
        Set objADOStream = Nothing
        If Err.Number = 0 Then
            ' download ok
            HTTPDownload = "Download OK"            
        Else
            ' error
            HTTPDownload = "Download Error " & Err.Number
            Err.Clear
        End If
    Else
        HTTPDownload = "HTTP Error " & objXMLHTTP.Status
    End if

    Set objXMLHTTP = Nothing
    On Error GoTo 0
End Function


Function WriteMsgID(TempFileStr, MsgID)
    Dim fso, SeekFile, TextLine

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set SeekFile = fso.OpenTextFile(TempFileStr, ForWriting, True, TristateTrue)
    SeekFile.WriteLine MsgID

    SeekFile.Close
End Function

Function ReadMsgID(TempFileStr)
    Dim fso, SeekFile, TextLine

    Set fso = CreateObject("Scripting.FileSystemObject")
    
    If fso.FileExists(TempFileStr) Then
        SeekFileExists=TRUE
        Set SeekFile = fso.OpenTextFile(TempFileStr, ForReading, True, TristateTrue)
        Do While SeekFile.AtEndOfStream <> True
            TextLine = SeekFile.ReadLine
        Loop

        SeekFile.Close
    Else
        SeekFileExists=FALSE
        TextLine = "1"
    End If


    ReadMsgID = TextLine
End Function


Function HTTPPost(sUrl, sRequest)
    set oHTTP = CreateObject("Microsoft.XMLHTTP")
    oHTTP.open "POST", sUrl,false
    oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    oHTTP.setRequestHeader "Content-Length", Len(sRequest)
    oHTTP.send sRequest
    HTTPPost = oHTTP.responseText
End Function

Function SendResponse(strChatID, strTelegram)
    'if chat id is negative skip this function
    'no response to group messages
    
    If CDbl(strChatID) > 0 Then
        sTmpUrl = "https://api.telegram.org/bot" & sAPI_ID & "/sendMessage"
'       sTmpRequest = "text=" & strTelegram & "&chat_id=" & strChatID & "&disable_notification=true"
        sTmpRequest = "chat_id=" & strChatID & "&text=" & strTelegram  

        sTmpResponse = HTTPPost(sTmpUrl, sTmpRequest)
'debug      wscript.echo(sTmpResponse)
    Else
'debug      wscript.echo("Not send")
    End If
End Function

Function GetMessage()
    sUrl = "https://api.telegram.org/bot" & sAPI_ID & "/getupdates"
    sRequest = "offset=1"
    sResponse = HTTPPost(sUrl, sRequest)

    OldMsgID=ReadMsgID(MsgIdFile)
    OldUpdateID=GetTelegramUpdateID(sResponse)

    wscript.echo("last message_id: " & OldMsgID)
    wscript.echo("last update_id: " & OldUpdateID)

    sResponseBackup=sResponse

    Do While InStr(sResponse,"message_id") > 0
        TempStr=Right(sResponse,Len(sResponse)-InStr(sResponse,"message_id")-11)
        TempStr2=Left(TempStr,Instr(TempStr,",")-1)
        If CDbl(TempStr2) > CDbl (OldMsgID) Then
            ' new message
            TempMsgType=GetMsgType(TempStr)
            TempChatID=GetChatID(TempStr)


            Select Case UserConfig(TempChatID)
            Case "kwaliteit"
                wscript.echo("-kwaliteit-")
                TempTarget="******

[ Voor 0% gewijzigd door F_J_K op 29-03-2023 15:52 . Reden: ik ben zo vrij code tags om de code te zetten ]

Alle reacties


Acties:
  • 0 Henk 'm!

  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB

Front verplichte underscores

Welke taal? Ik heb even tags om de code gezet om het meer leesbaar te krijgen.

Je vraag gaat minder over Telegram als tool en meer over programmeren, gebruik van de API.. Ik verplaats je vraag dan ook even naar de dev-buren.

Verder lees ik o.a over resoluties op https://core.telegram.org/api/files dus misschien valt daar wat inspiratie op te doen.

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)