Answer the question
In order to leave comments, you need to log in
How to transfer a file to telegram?
the bot itself was created
_________________
there is a field with an input type file (screen below)
you need to transfer it to telegrams, as well as the data from the inputs I pass the
inputs (they are displayed successfully)
$('.button').on('click', function(e) {
var phone = $('#c_phone-number').val();
var email = $('#c_email').val();
$.ajax({
url: myajax.url,
type: 'POST',
data: {
action: 'request',
phone: phone,
email: email,
},
}).done(function(data){
$('#c_phone-number, #c_email ).val('');
});
return false;
});
<?php
add_action('wp_ajax_request', 'request_action');
add_action('wp_ajax_nopriv_request', 'request_action');
function request_action() {
$chat_id = 'свой номер чата';
$token = 'свой номер токена';
$phone = $_POST['phone'];
$email = $_POST['email'];
$text .= "<b>Сообщение с сайта</b>\n\n";
$text .= "Телефон: ".$phone."\n";
$text .= "Email: ".$email."\n";
$text = urlencode($text);
$str = "https://api.telegram.org/bot".$token."/sendMessage?chat_id=".$chat_id."&parse_mode=html&text=".$text;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
wp_die();
}
Answer the question
In order to leave comments, you need to log in
Use the sendDocument
method
Limitation - file size up to 50 MB
https://core.telegram.org/bots/api#senddocument
And use wp_remote_get / wp_remote_post functions to send requests.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question