Advertisement
tristamoff

Untitled

Feb 14th, 2017
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. function teleToLog($log) {
  2.   $myFile = 'log.txt';
  3.   $fh = fopen($myFile, 'a') or die('can\'t open file');
  4.   if ((is_array($log)) || (is_object($log))) {
  5.     $updateArray = print_r($log, TRUE);
  6.     fwrite($fh, $updateArray."\n");
  7.   } else {
  8.     fwrite($fh, $log . "\n");
  9.   }
  10.   fclose($fh);
  11. }
  12.  
  13. function getUserRequest($text, $chat_id) {
  14.   $hello = array();
  15.   $hello[] = 'привет';
  16.   $hello[] = 'хай';
  17.   $hello[] = 'здорова';
  18.   $hello[] = 'здравствуйте';
  19.   $hello[] = 'здрасьте';
  20.   $hello[] = 'йо';
  21.  
  22.   $bot_hello = array();
  23.   $bot_hello[] = 'И тебе привет';
  24.   $bot_hello[] = 'Привет от голоса';
  25.   $bot_hello[] = 'Доброго времени суток';
  26.   $bot_hello[] = 'Привет привет';
  27.  
  28.   if (in_array(mb_strtolower($text), $hello)) {
  29.     //пользователь поздоровался.
  30.     //случайная фраза привет от бота
  31.     $bot_resp = $bot_hello[rand(0, (count($bot_hello) - 1))];
  32.     $data = array(
  33.       'text' => $bot_resp,
  34.       'chat_id' => $chat_id,
  35.     );
  36.     requestToTelegram($data);
  37.   }
  38. }
  39.  
  40. function requestToTelegram($data, $type = 'sendMessage') {
  41.   if( $curl = curl_init() ) {
  42.     curl_setopt($curl, CURLOPT_URL, API_URL . $type);
  43.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  44.     curl_setopt($curl, CURLOPT_POST, TRUE);
  45.     curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  46.     curl_exec($curl);
  47.     curl_close($curl);
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement