@@ -117,6 +117,107 @@ String UniversalTelegramBot::sendPostToTelegram(String command, JsonObject& payl
117
117
return response;
118
118
}
119
119
120
+ String UniversalTelegramBot::sendImageFromFileToTelegram (File* file, String chat_id){
121
+
122
+ String response = " " ;
123
+ long now;
124
+ bool responseRecieved;
125
+ // Connect with api.telegram.org
126
+ if (client->connect (HOST, SSL_PORT)) {
127
+ // POST URI
128
+ client->print (" POST /sendPhoto?chat_id=" +chat_id); client->println (" HTTP/1.1" );
129
+ // Host header
130
+ client->print (" Host:" ); client->println (HOST);
131
+ // JSON content type
132
+ client->println (" Content-Type: multipart/form-data, boundary=UH3xBZZtzewr09oPP" );
133
+ client->print (" Content-Length:" ); client->println (file->size () + 175 );
134
+ client->println (); // 2
135
+ client->println (" --UH3xBZZtzewr09oPP" ); // 19 + 2
136
+ client->println (" content-disposition: form-data; name=\" photo\" ; filename=\" img.jpg\" " ); // 64 + 2
137
+ client->println (" Content-Type: image/jpeg" ); // 24 + 2
138
+ client->println (" Content-Transfer-Encoding: binary" ); // 33 + 2
139
+ client->println (); // 2
140
+
141
+
142
+ Serial.println (" data" );
143
+ int count = 0 ;
144
+ char ch;
145
+ while (file->available ()) {
146
+ ch = file->read ();
147
+ client->println (ch);
148
+ // Serial.println(ch);
149
+ count++;
150
+ if (count > 50 ){
151
+ ESP.wdtFeed ();
152
+ Serial.println (" feed" );
153
+ count = 0 ;
154
+ }
155
+ }
156
+
157
+
158
+ client->println (); // 2
159
+ client->println (" --UH3xBZZtzewr09oPP--" ); // 21 + 2
160
+ // // Content length
161
+ // //int length = payload.measureLength();
162
+ // client->print("Content-Length:"); client->println(file->size());
163
+ // Serial.println(file->size());
164
+ // // End of headers
165
+ // client->println();
166
+ //
167
+ // Serial.println("data");
168
+ // int count = 0;
169
+ // char ch;
170
+ // while (file->available()) {
171
+ // ch = file->read();
172
+ // client->println(ch);
173
+ // //Serial.println(ch);
174
+ // count++;
175
+ // if(count > 50){
176
+ // ESP.wdtFeed();
177
+ // Serial.println("feed");
178
+ // count = 0;
179
+ // }
180
+ // }
181
+
182
+ Serial.println (" Done" );
183
+ Serial.println (" Done" );
184
+ Serial.println (" Done" );
185
+ Serial.println (" Done" );
186
+
187
+
188
+ count = 0 ;
189
+ int ch_count=0 ;
190
+ char c;
191
+ now=millis ();
192
+ responseRecieved=false ;
193
+ while (millis ()-now<1500 ) {
194
+ // if(count > 100){
195
+ // ESP.wdtFeed();
196
+ // Serial.println("feed1");
197
+ // count = 0;
198
+ // }
199
+ // count++;
200
+ while (client->available ()) {
201
+ char c = client->read ();
202
+ // Serial.write(c);
203
+ if (ch_count < maxMessageLength) {
204
+ response=response+c;
205
+ ch_count++;
206
+ }
207
+ responseRecieved=true ;
208
+ }
209
+ if (responseRecieved) {
210
+ Serial.println ();
211
+ Serial.println (response);
212
+ Serial.println ();
213
+ break ;
214
+ }
215
+ }
216
+ }
217
+
218
+ return response;
219
+ }
220
+
120
221
121
222
bool UniversalTelegramBot::getMe () {
122
223
String command=" bot" +_token+" /getMe" ;
0 commit comments