Advertisement
Guest User

bot.php

a guest
Jul 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.16 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6.  
  7. ob_start();
  8.  
  9. //----- CONFIGURACION -----//
  10. define('API_KEY','TUTOKEN');//addtoken
  11. ///// FUNCIONES GLOBALES /////
  12. function Https($method,$datas){
  13. $url = "https://api.telegram.org/bot".API_KEY."/".$method;
  14. $ch = curl_init();
  15. curl_setopt($ch,CURLOPT_URL,$url);
  16. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  17. curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
  18. $res = curl_exec($ch);
  19.  
  20. if(curl_error($ch)){ var_dump(curl_error($ch)); }
  21. else{ return json_decode($res); }
  22. }
  23. function BotAccion($chat_id, $action){
  24. Https('sendChataction',array(
  25. 'chat_id'=>$chat_id,
  26. 'action'=>$action
  27. ));
  28. }
  29.  
  30.  
  31. function EnviarRep($chat_id, $text,$replymarkup, $msj_id){
  32. Https('sendMessage',array(
  33. 'chat_id'=>$chat_id,
  34. 'text'=>$text,
  35. 'parse_mode'=>'HTML',
  36. 'reply_to_message_id'=>$msj_id,
  37. 'reply_markup'=>$replymarkup
  38. ));
  39. }
  40.  
  41. function EnviarGifs($chat_id, $photo, $caption){
  42. Https('sendDocument',array(
  43. 'chat_id'=>$chat_id,
  44. 'document'=>$photo,
  45. 'caption'=>$caption
  46. ));
  47. }
  48. function DeleteMSJ($chat_id, $msj_id){
  49.     Https('deleteMessage',array(
  50.         'chat_id'=>$chat_id,
  51.         'message_id'=>$msj_id));
  52. }
  53. function EnviarMensaje($chat_id, $text,$replymarkup){
  54. Https('sendMessage',array(
  55. 'chat_id'=>$chat_id,
  56. 'text'=>$text,
  57. 'parse_mode'=>'HTML',
  58. 'reply_markup'=>$replymarkup
  59. ));
  60. }
  61.  
  62.  
  63.  
  64. function EnviarFoto($chat_id, $photo, $caption){
  65. Https('sendPhoto',array(
  66. 'chat_id'=>$chat_id,
  67. 'photo'=>$photo,
  68. 'caption'=>$caption
  69. ));
  70. }
  71.  
  72. }
  73. function EnviarTelefono($chat_id, $phonenumber, $firstname, $vcard){
  74. Https('sendContact',array(
  75. 'chat_id'=>$chat_id,
  76. 'phone_number'=>$phonenumber,
  77. 'first_name'=>$firstname,
  78. 'vcard'=>$vcard
  79. ));
  80. }
  81.  
  82.  
  83. function KickMember($chat_id, $user_id){
  84. Https('kickChatMember', array(
  85.     'chat_id'=>$chat_id,
  86.     'user_id'=>$user_id));
  87. Https('unbanChatMember', array(
  88.     'chat_id'=>$chat_id,
  89.     'user_id'=>$user_id));
  90.    
  91. }
  92.  
  93.  
  94. ///// VARIABLES GLOBALES /////
  95. $update = json_decode(file_get_contents('php://input'));
  96. $mensaje = $update->message; // Datos del Mensaje que recibimos
  97. $tipo_de_chat = $mensaje->chat->type; // Tipo de chat 'private','group','supergroup','channel'
  98. $msj_chat_id = $mensaje->chat->id;
  99. $msj_de_id = $mensaje->from->id; // ID del usuario que recibimos el mensaje
  100. $msj_de_fname = $mensaje->from->first_name; // NOMBRE del usuario que recibimos el mensaje
  101. $msj_texto = $mensaje->text; // Texto del Mensaje que recibimos
  102. $msj_id = $mensaje->message_id;
  103. //CALLBACK//
  104. $callbackDatos = $update->callback_query;
  105. $callbku = $callbackDatos->inline_message_id;
  106. $cb_chat_tipo = $callbackDatos->message->chat->type; // Tipo de chat 'private','group','supergroup','channel'
  107. $cb_datos = $callbackDatos->data; // Texto que recibimos del calllback_query
  108. $cb_chat_id = $callbackDatos->message->chat->id;
  109.  
  110.  
  111. $cb_message = $callbackDatos->message->text;
  112. $cb_user_id = $callbackDatos->from->id;
  113. $cb_user_name = $callbackDatos->from->first_name;
  114. $cb_id = $callbackDatos->message->message_id;
  115. $results_count = 5;
  116. //edicion de mensajes//
  117. $edits = $update-edited_message;
  118. $edit_id = $edits->message_id;
  119. //INLINE//
  120. $inlineDatos = $update->inline_query;
  121. $inline_id = $inlineDatos->id;
  122. $inline_from = $inlineDatos->from->id;
  123. $inline_text = $inlineDatos->query;
  124. if(isset($mensaje)){
  125. if($tipo_de_chat == 'private'){ // PRIVADO
  126. switch($msj_texto){
  127. case '/help':
  128. EnviarMensaje($msj_de_id, 'Ayuda',false);
  129.  
  130. default:
  131. EnviarMensaje($msj_de_id,'Uh? No entendi', false);
  132. break;
  133. }
  134. }else if($tipo_de_chat == 'supergroup'){ // SUPERGRUPO
  135. switch($msj_texto){
  136. case '/start':
  137. EnviarMensaje($msj_chat_id, 'Para ver la ayuda pon /help',false);
  138. break;
  139. case '/help':
  140.  
  141.     $keyboard = json_encode(
  142.         array('inline_keyboard'=>array(array(
  143.          array('text'=>"Ir al privado","callback_data"=>"priv")));
  144. EnviarMensaje($msj_chat_id, 'Ve al privado',$keyboard);
  145.        
  146. break;
  147.  
  148. }else if(isset($callbackDatos)){
  149.     if($cb_chat_tipo == 'private'){//callback de privado
  150.   switch($cb_datos){
  151.    case 'priv':
  152.     EnviarMensaje($cb_user_id,'Ya estas en el privado',false);
  153.     break;
  154. }}else if($cb_chat_tipo =='supergroup'){
  155.       switch($cb_datos){
  156. case 'priv':
  157. EnviarMensaje($cb_chat_id, 'abre al privado y pon /help',false)
  158. break;
  159. }}}
  160. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement