Closed pablosouza10 closed 6 years ago
define new parameter as last last command and save it in database or in a text file with the userid as the file name, and in every step read the last command for exp. ques1, ques2 , ... and send your question related to last command.
if you need more help don't hesitate to tell me.
Thanks a lot, I will try...
I need more help:
the questions are fixed like this:
user: /help bot: what your Branch? user: 15 bot: what your IP? user: 16 bot: what your Problem? user: some text...
How wait the user reply without go to another question?
the last step, I need store the users inputs to send to another group.
I have a sample code for this problem can help you Contact me on telegram @getfeedbackbot
Thanks, I use your bot with help of google translate :). Can you send me the sample code?
Best regards
Thanks @Mohsen322 help me so much!!!
i use this example code in my project, you can get some idea
`$bot_id = "Your_Token"; $telegram = new Telegram($bot_id);
// Take text and chat_id from the message $text = $telegram->Text(); $chat_id = $telegram->ChatID();
// Reply condition $replycon = $telegram->ReplyToMessageText();
if (!is_null($text) && !is_null($chat_id)) { if ($text == '/help') {
$reply = 'question1';
$frc = $telegram->buildForceReply(true);
$content = ['chat_id' => $chat_id, 'reply_markup' => $frc, 'text' => $reply];
$telegram->sendMessage($content);
} elseif ($replycon == 'question1') {
// User Answer is stored in $text Do everything you want on $text , stor it in a text file or in Database
InputData($chat_id ,$text);
$reply = 'question2';
$frc = $telegram->buildForceReply(true);
$content = ['chat_id' => $chat_id, 'reply_markup' => $frc, 'text' => $reply];
$telegram->sendMessage($content);
}
elseif ($replycon == 'question2') {
// User Answer is stored in $text Do everything you want on $text , stor it in a text file or in Database
InputData($chat_id ,$text);
$reply = 'Thank you to take part in this survey';
$content = ['chat_id' => $chat_id, 'text' => $reply];
$telegram->sendMessage($content);
//Send your collected data to a group $group_id : the target group id
SendGroup($chat_id ,$group_id);
} else {
$reply = 'Please answer in reply to qustion'; $content = ['chat_id' => $chat_id, 'text' => $reply]; $telegram->sendMessage($content); } }
function InputData($chatID,$data){
$myFile = $chatID.".txt";
$fle = fopen($myFile, 'a') or die("can't open file");
fwrite($fle, $chatID ."\n\n");
fclose($fle);
}
function SendGroup($chatID,$groupID){
$myFile = $chatID.".txt";
$fle = fopen($myFile, 'r') or die("can't open file");
$reply = fread($fle,filesize($myFile));
fclose($fle);
$content = ['chat_id' => $groupID, 'text' => $reply];
$telegram->sendMessage($content);
}`
as you see in this method, used from "forcereply" to get the exact answer for the question and go to the next question after that.
The important part is that the " $telegram->ReplyToMessageText();" object doesn't exist in default " Telegram.php" File and you need to add this object to the class as follow
`/**
\return the String reply_to_message Text. */
public function ReplyToMessageText() { return $this->data['message']['reply_to_message']['text']; }`
I wish that this code could solve your issue, if you want more help please don't hesitate to tell me.
@emobin Thank you so much!!! Will help me sure.
Hi, a need this:
I dont know do the steps 3 and 5 to store the answer and to send next question only after the user answer previous question. Can send a example code?