I am trying to lock the keys in the custom keyboard so the user can tap multiple buttons in the custom keyboard before sending the message. The default is you tap a custom keyboard button and message is sent, like with trivia bot. Any ideas on how to do this or if it is even possible?
If I understood right, what you want to do is multiselect (checkbox); there is no such function in telegram, but you can implement it a bit differently.
First, you send message with inline buttons and empty checkboxes with some text:
switch ($callback_query){
case 'choose':
$inline_keyboard = [
[
['text'=>'☐ 1', 'callback_data'=>"n1"],
['text'=>'☐ 2', 'callback_data'=>"n2"],
['text'=>'☐ 3', 'callback_data'=>"n3"]
],
[
['text'=>'☐ 4', 'callback_data'=>"n4"],
['text'=>'☐ 5', 'callback_data'=>"n5"]
],
[
['text'=>'Next', 'callback_data'=>"$someData"]
]
];
$keyboard=["inline_keyboard"=>$inline_keyboard];
$replyMarkup = json_encode($keyboard);
sendMessage($chat_id_callback, "Lorem ipsum dolor sit amet.", $replyMarkup);
break;
// When user is clicking on the buttons You process it with another case with all possible buttons in it and using telegram api to editMessageReplyMarkup
case "n1":
case "1":
case "n2":
case "2":
case "n3":
case "3":
case "n4":
case "4":
case "n5":
case "5":
$empty_checkbox = "☐";
$galochka = "✔";
if (substr($data,0,1)== "n"){
$is_checked = TRUE;
} else {
$is_checked = FALSE;
}
if ($is_checked){
$what_is_checked = substr($data, 1);;
} else {
$what_is_checked = $data;
}
// $output is variable, in wich telegram data is stored, which came through webhook
$text1 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][0]['text'];
$text2 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][1]['text'];
$text3 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][2]['text'];
$text4 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][0]['text'];
$text5 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][1]['text'];
$room_callback_data1 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][0]['callback_data'];
$room_callback_data2 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][1]['callback_data'];
$room_callback_data3 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][0][2]['callback_data'];
$room_callback_data4 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][0]['callback_data'];
$room_callback_data5 = $output['callback_query']['message']['reply_markup']['inline_keyboard'][1][1]['callback_data'];
if ($what_is_checked == "1"){
if ($is_checked == TRUE) {
$text1 = $galochka . " 1";
$room_callback_data1 = "1";
} else {
$text1 = $empty_checkbox . " 1";
$room_callback_data1 = 'n2';
}
} elseif ($what_is_checked == "2"){
if ($is_checked == TRUE) {
$text2 = $galochka . " 2";
$room_callback_data2 = "2";
} else {
$text2 = $empty_checkbox . " 2";
$room_callback_data2 = 'n2';
}
} elseif ($what_is_checked == "3"){
if ($is_checked == TRUE) {
$text3 = $galochka . " 3";
$room_callback_data3 = "3";
} else {
$text3 = $empty_checkbox . " 3";
$room_callback_data3 = 'n3';
}
} elseif ($what_is_checked == "4"){
if ($is_checked == TRUE) {
$text4 = $galochka . " 4";
$room_callback_data4 = "4";
} else {
$text4 = $empty_checkbox . " 4";
$room_callback_data4 = 'n4';
}
} elseif ($what_is_checked == "5"){
if ($is_checked == TRUE){
$text5 = $galochka . " 5";
$room_callback_data5 = "5";
} else {
$text5 = $empty_checkbox . " 5";
$room_callback_data5 = 'n5';
}
}
$inline_keyboard = [
[
['text'=>$text1, 'callback_data'=>$room_callback_data1],
['text'=>$text2, 'callback_data'=>$room_callback_data2],
['text'=>$text3, 'callback_data'=>$room_callback_data3]
],
[
['text'=>$text4, 'callback_data'=>$room_callback_data4],
['text'=>$text5, 'callback_data'=>$room_callback_data5]
],
[
['text'=>'Next', 'callback_data'=>"remont"]
]
];
$keyboard=["inline_keyboard"=>$inline_keyboard];
$replyMarkup = json_encode($keyboard);
editMessageReplyMarkup($chat_id_callback, $message_id, $replyMarkup);
break;
}
In the second case, you are just checking which button was pressed and simply change empty box on check mark.
Also, you need to use answerCallbackQuery, to work properly:
function send_answerCallbackQuery($callback_query_id, $text ='', $alert = 0){
file_get_contents($GLOBALS['api']."/answerCallbackQuery?callback_query_id=".$callback_query_id . '&text=' . $text . '&show_alert=' . $alert);
}
if (isset($output['callback_query'])) {
send_answerCallbackQuery($output['callback_query']['id']);
}
It's a default behavior to preserve custom keyboard unless you set one_time_keyboard = True or return a ReplyKeyboardHide to a user.
See docs: https://core.telegram.org/bots/api#replykeyboardmarkup
Also you can send the same keyboard in a reply message every time you want to make sure the keyboard is displayed.
Related
I have this if else statement that runs perfectly fine on my ExamController.cs but I wanted to use a switch statement to make it more easier to read. The only thing I added to the switch statement was the ExamId.
How come this if else statement works but not my switch case. The error has to do with the return but I didn't make any changes to the return.
if (model.SearchType == "School")
{
result = FindExams((e) => e.School.School_Name.Contains(model.SearchInput));
}
else if (model.SearchType == "Exam Date")
{
result = FindExams((e) => e.Exam.ExamDate >= model.StartDate.Date && e.Exam.ExamDate <= model.EndDate.Date);
}
else if (model.SearchType == "District")
{
result = FindExams((e) => e.District.Name.Contains(model.SearchInput));
}
else if (model.SearchType == "ID")
{
result = FindExams((e) => e.Student.ID.Contains(model.SearchInput));
}
else if (model.SearchType == "First Name")
{
result = FindExams((e) => e.Student.FirstName.Contains(model.SearchInput));
}
else if (model.SearchType == "Last Name")
{
result = FindExams((e) => e.Student.LastName.Contains(model.SearchInput));
}
return result.OrderByDescending(r => r.ExamDate);
Switch Statement
switch (model.SearchType)
{
case "School":
result = this.FindExams((e) => e.School.School_Name.Contains(model.SearchInput));
break;
case "ExamDate":
result = FindExams((e) => e.Exam.ExamDate >= model.StartDate.Date && e.Exam.ExamDate <= model.EndDate.Date);
break;
case "District":
result = this.FindExams((e) => e.District.Name.Contains(model.SearchInput));
break;
case "ID":
result = this.FindExams((e) => e.Student.ID.Contains(model.SearchInput));
break;
case "First Name":
result = this.FindExams((e) => e.Student.FirstName.Contains(model.SearchInput));
break;
case "Last Name":
result = this.FindExams((e) => e.Student.LastName.Contains(model.SearchInput));
break;
case "Exam Id":
int examId = int.Parse(model.SearchInput);
result = this.FindExams((e) => e.Exam.Exam_Id == examId);
break;
}
return result.OrderByDescending(r => r.ExamDate);
The two code snippets differ at these lines:
else if (model.SearchType == "Exam Date")
And
case "ExamDate":
As you can see they check two different strings.
It should be:
case "Exam Date":
Right now , I am working on a project. I have to build some rest full api's for android application using Woo-Commerce CLIENT REST API.
Everything is working fine, but the data i'm getting is unnecessary. So can anybody tell me, how to overcome from this problem.
e.g. I am getting this data
{
product_categories: [
{
id: 8,
name: "Cakes",
slug: "cakes",
parent: 0,
description: "Love is like a good cake; you never know when it's coming, but you'd better eat it when it does!",
count: 11
},
{
id: 9,
name: "Breads",
slug: "breads",
parent: 0,
description: "All sorrows are less with bread. ",
count: 3
},
{
id: 10,
name: "Pastries",
slug: "pastries",
parent: 0,
description: "I'm not a vegetarian! I'm a pastries-ian!",
count: 6
}
but i do not want slug,parent, description parameters.
Thanks in advance.
Your Problems is " " missing in key Ex: "ID", "name" and
You use this function json_pretty() for json format.
function json_pretty($json, $html = false) {
$out = ''; $nl = "\n"; $cnt = 0; $tab = 4; $len = strlen($json); $space = ' ';
if($html) {
$space = ' ';
$nl = '<, $html = false)br/>';
}
$k = strlen($space)?strlen($space):1;
for ($i=0; $i<=$len; $i++) {
$char = substr($json, $i, 1);
if($char == '}' || $char == ']') {
$cnt --;
$out .= $nl . str_pad('', ($tab * $cnt * $k), $space);
} else if($char == '{' || $char == '[') {
$cnt ++;
}
$out .= $char;
if($char == ',' || $char == '{' || $char == '[') {
$out .= $nl . str_pad('', ($tab * $cnt * $k), $space);
}
}
return $out;
}
How to user this function ?
$pre = '{"status": 1,"message": "My Collection downloaded successfully.","myCollections":';
$postd = ' }';
$jsa_data = json_encode($res_arr); // pass your Array
echo $finalJson = json_pretty($pre.$jsa_data.$postd);
Out put
{
"status": 1,
"message": "All Post downloaded successfully",
"postData": [
{
"id": 8,
"name": "Cakes",
"slug": "cakes",
"parent": 0,
"description": "Love is like a good cake; you never know when it's coming, but you'd better eat it when it does!",
"count": 11
},
{
"id": 9,
"name": "Breads",
"slug": "breads",
"parent": 0,
"description": "All sorrows are less with bread. ",
"count": 3
},
{
"id": 10,
"name": "Pastries",
"slug": "pastries",
"parent": 0,
"description": "I'm not a vegetarian! I'm a pastries-ian!",
"count": 6
}
]
}
Check it Json LINT http://jsonlint.com/
I have a columnrange graph and want to define the color of a single bar line. If you see the second set in the picture. depending on a certain condition I would liek to change this to different color. $schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to); if endate is not greater than today then change color to red.
How would I do this?
in view
$('#container').highcharts({
'chart':{
'type':'columnrange',
'inverted':true,
},
'exporting':{
'enabled':true
},
'title':{
'text':'Projects incomplete in 2013'
},
'xAxis':{
'categories':<?=$cat?>
},
'yAxis':{
'title':'Date',
'type':'datetime',
'dateTimeLabelFormats':{
'month':'%b'
},
'min':Date.UTC(2013,00,01)
},
'tooltip':{
formatter: function(){
return '<b>' +this.series.name + ':</b> '+ Highcharts.dateFormat('%e %b, %Y', this.point.low) + ' - ' + Highcharts.dateFormat('%e %b, %Y', this.point.high) +'<br/>' ;
}
},
'legend':{
'enabled':false
},
'series':[
{
'name':'Start - End',
'data':<?=$data?>
},
{
'name':'Forecast',
'data':<?=$schedule?>,
'color': 'green'
},
{
'name':'Actual',
'data':<?=$complete?>,
'color': 'yellow'
}
]
});
In my controller I have
public function actionGraph(){
$command = Yii::app()->db->createCommand("
SELECT
view_webprojectreport.PROJECT,
view_webprojectreport.StartDATE,
view_webprojectreport.ProjectEndDate,
view_webprojectreport.PERCENT,
view_webprojectreport.ASAAREA
FROM
view_webprojectreport
WHERE
view_webprojectreport.StartDATE >= '2013' AND
view_webprojectreport.ProjectEndDate IS NOT NULL AND
view_webprojectreport.PERCENT < 100
ORDER BY
view_webprojectreport.PERCENT DESC
")->queryAll();
$series = array();
$cat = array();
$totalLength = array();
$schedule = array();
$complete = array();
foreach ($command as $key => $model) {
$cat[] = $model['PROJECT'];
$date_from = (strtotime($model['StartDATE']) + 1*86400)*1000;
$date_to = (strtotime($model['ProjectEndDate']) + 1*86400)*1000;
$totalLength[] = array($date_from,$date_to);
$today = time();
$startdate = strtotime($model['StartDATE']);
$enddate = strtotime($model['ProjectEndDate']);
$diff_total = $enddate - $startdate;
$diff_today = $today - $startdate;
$percentage_date=round(($diff_today/$diff_total)*100,2);
$duration = ( ((strtotime($model['ProjectEndDate']) + 1*86400)*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000) );
$burn = ((time() )*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000);
$pBurned = $burn/$duration;
$time = $time = strtotime( ($date_from + $pBurned) );
//echo date('Y-m-d') . " : " . date('Y-m-d',strtotime($model['ProjectEndDate'])) . "<br>";
// place check for calculating if project end date is in past
$schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to);
$percentage_to_get = round((float)$model['PERCENT'],2);
$percentage_of_days = ((int)$model['PERCENT'] == 0)? 0 : floor($diff_total/100*$percentage_to_get);
//echo date('Y-m-d', $startdate) . " : " . date('Y-m-d', $startdate + $percentage_of_days ) . "<br>";
//echo $startdate . " : " . ($startdate + $percentage_of_days) . "<br>";
$percentComplete = (($startdate + $percentage_of_days)+ 1*86400)*1000;
$complete[] = array($date_from,$percentComplete);
}
$series = array("series"=>array(
array(
'name'=>'Start - End',
'data'=>$totalLength
),
array(
'name'=>'Forecast',
'data'=>$schedule,
'color'=> 'green'
),
array(
'name'=>'Actual',
'data'=>$complete,
'color'=> 'yellow'
)
));
print_r($series);
$this->render('graph',array(
'cat'=>json_encode($cat),
"data"=>json_encode($totalLength),
"schedule"=>json_encode($schedule),
"complete"=>json_encode($complete),
"series"=>json_encode($series)
));
}
output of schedule
[[1357689600000,1372064004000],[1360972800000,1.3686588e+12],[1359158400000,1372064004000],[1.3630464e+12,1365721200000],[1359417600000,1372064004000],[1.3709916e+12,1372064004000],[1.3686588e+12,1372064004000],[1.3681404e+12,1372064004000],[1.3699548e+12,1372064004000],[1366930800000,1372064004000]]
How would I incorporate the color in this?
$schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to);
I have found http://jsfiddle.net/Q2JMF/2/ and trying to implement but not working. graph displays nothing
My example on jsfiddle http://jsfiddle.net/shorif2000/z4HXX/2/
Your point should be object like :
{
y:10,
color: 'red'
}
So data should looks like:
data:[{
y:10,
color: 'red'
},4,5,6,7,7]
How to prepare correct structure:
http://php.net/manual/en/function.json-encode.php
Kindly help on the code below. What happens is that I get the latitude and longitude of the name of a place when I click on a button. However, of late, it is not working. It prints that "Address x failed to Geocode. Received status " Note that x is a given address and no status code is given.
$id=$_REQUEST['id'];
define("MAPS_HOST", "maps.googleapis.com");
define("KEY", "xxxxxxx");
$query = "SELECT * FROM markers WHERE mid = $id LIMIT 1";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?address=";
if($row = #mysql_fetch_assoc($result)){
$geocode_pending = true;
$address = $row["address"];
while ($geocode_pending) {
$request_url = $base_url . urlencode($address) . "&sensor=false&key=" . KEY;
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
//$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
//$lat = $coordinatesSplit[1];
//$lng = $coordinatesSplit[0];
list($lat,$lng) = explode(",",$coordinates);
$query = sprintf("UPDATE markers " .
" SET lat = '%s', lng = '%s' " .
" WHERE mid = '%s' LIMIT 1;",
mysql_real_escape_string($lng),
mysql_real_escape_string($lat),
mysql_real_escape_string($id));
$update_result = mysql_query($query);
if (!$update_result) {
die("Invalid query: " . mysql_error());
}else{
echo "$lat;$lng";
}
} else if (strcmp($status, "620") == 0) {
// sent geocodes too fast
$delay += 100000;
} else {
// failure to geocode
$geocode_pending = false;
echo "Address " . $address . " failed to geocode. ";
echo "Received status " . $status . "
\n";
}
usleep($delay);
}
}
I'm not sure on which API your code is based on, but the response of the current API will not work with these lines:
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
There are no elements Response,Status or code, furthermore the response will not contain a numeric status-code.
use this instead:
$status = $xml->status;
if (strcmp($status, "OK") == 0) {
To fix the rest of the code please take a look at the structure of the returned XML, there are also no elements Placemark,Point and coordinates.
it should be:
$lat = $xml->result->geometry->location->lat;
$lng = $xml->result->geometry->location->lng;
Trying to do a count on these lines COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
but it keeps returning the same numbers for all three. So I'm trying to add a Where for each one, Example Count(isContractor where isContractor = 'yes') as contractorCount but getting errors please help, thank you.
<?php
clASs EfficiencyController extends DooController
{
function getEfficiency(){
include './protected/config/db.conf.php';
Doo::db()->setDb($dbconfig, 'local_network');
$Vendor = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['Vendor'] : $_GET['Vendor'];
$date = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['date'] : $_GET['date'];
$level = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['level'] : $_GET['level'];
switch($level) {
case "Region":
case "area":
$Market99="";
break;
default:
$Market99=$level;
break;
}
{
//
// LUCENT,NORTEL
//
$query = " SELECT
DayKey,
Market99,
Region,
areaName,
Sum(Total_Sites) as totalCount,
Max(engineerCount) AS engineerCount,
Max(managerCount) AS managerCount,
Max(contractorCount) AS contractorCount,
SC_Type,
Sum(Total_Carriers),
Sum(Total_Sectors),
Vendor
FROM
network.envEquipSummaryConfig a
Left Join
(SELECT
market,
areaName,
COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
FROM
employee.employees
GROUP BY market
ORDER BY COUNT(market) DESC) b ON a.Market99 = b.market
Where
a.DayKey <= \"$date\" and a.Vendor = \"$Vendor\"
Group By Market99 asc";
switch($level) {
case "region":
$query = $query. " order by region ASC";
break;
case "area":
$query = $query. " order by areaName ASC";
break;
default;
$query = $query. " order by Market99 ASC";
break;
}
}
//echo $query; exit;
$this->setContentType('xml');
$result = Doo::db()->fetchAll($query);
printf("<root>\n");
if(count($result) > 0)
foreach($result AS $row) {
printf("\t<data>\n");
printf("\t\t<date>%s</date>\n",$row["DayKey"]);
printf("\t\t<vName>%s</vName>\n",$row["Vendor"]);
printf("\t\t<location>%s</location>\n",$row["Market99"]);
printf("\t\t<toCount>%s</toCount>\n",$row["totalCount"]);
printf("\t\t<enCount>%s</enCount>\n",$row["engineerCount"]);
printf("\t\t<mnCount>%s</mnCount>\n",$row["managerCount"]);
printf("\t\t<cnCount>%s</cnCount>\n",$row["contractorCount"]);
printf("\t</data>\n");
}
printf("</root>\n");
}
}
?>
SELECT
market,
areaName,
COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
FROM
employee.employees
GROUP BY market
should be
Group By market,areaName at a guess.
Which is all it can be seeing as you've provided next to no useful information.