Answer the question
In order to leave comments, you need to log in
How to send a link to a file in telegram?
at least an approximate version of the
test fields is transferred without problems,
the essence is this:
we
send the file
on the server, we look at its format, if it doesn’t fit, we do nothing (or we can return an error),
if everything is ok, save it to a folder (create a new uploads folder) and send a link to the file in telegram
$('.request__button').on('click', function(e) {
var file_data = $('#inputfile').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
var surname = $('#c_surname').val();
var name = $('#c_name').val();
$.ajax({
url: myajax.url,
type: 'POST',
data: {
action: 'request',
surname: surname,
name: name,
files: form_data
},
}).done(function(data){
});
return false;
});
add_action('wp_ajax_request', 'request_action');
add_action('wp_ajax_nopriv_request', 'request_action');
function request_action() {
$chat_id = 'тут есть номер';
$token = 'тут тоже есть номер;
$surname = $_POST['surname'];
$name = $_POST['name'];
$text .= "<b>Сообщение с сайта</b>\n\n";
$text .= "Фамилия: ".$surname."\n";
$text .= "Имя: ".$name."\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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question