-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
36 lines (26 loc) · 989 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
include "bot.php"; //Import functions file
$token="Your Bot Token"; //Bot Token
$api="Your OpenAi Api Key";//openai ApiKey
$bot= new tgbot($token,$api); //create bot object
$data = json_decode(file_get_contents('php://input')); //Get Updates
//Getting User Message
$text=$data->message->text;
//Getting User Name And I'd
$firstname=$data->message->from->first_name;
//$lastname=$data->message->from->
$chat_id = $data->message->from->id;
//Checking The Message And Sending Reply
if($text=='/start'){
$bot->send_message($chat_id,"<b> Hello $firstname Welcome To Ai Bot\n\nthis Bot Created using openai Api\n\nUse /ask command To ask questions</b>","html");
}elseif($text=='/ask' or substr($text,0,4)=='/ask'){
$msg=explode("/ask ",$text);
$prompt=$msg[1];
if($prompt !=""){
$answer=$bot->get_answer($prompt);
$bot->send_message($chat_id, $answer,"html");
}else{
$bot->send_message($chat_id, "<b>send like this /ask your question</b>","html");
}
}
?>