I have a question about using editMessageReplyMarkup method in Telegram bot API in PHP.
I'm trying to provide user choose category and sub-category after with InlineKeyboardMarkup . But I want to make it with replacing one Keyboard with another.
I found method editMessageReplyMarkup which does exectly what I need , but for some reason it returns me false.
On the first screenshot you can see how bot sends me categories.
After I choose any of it next code is running:
if (is_array($update[count($update)-1]["callback_query"])) {
$chat_id = $update[count($update)-1]["callback_query"]["from"]["id"];
$requested_category = $update[count($update)-1]["callback_query"]['data'];
$message_answer_id = $update[count($update)-1]["callback_query"]['message']['message_id'];
send_sub_projects($user_model, $telegram, $chat_id, $requested_category, $message_answer_id);
}
Here is the method send_sub_projects
function send_sub_projects($user_model, $telegram, $chat_id, $category, $message_id) {
$subcategories = $user_model->get_sub_categories($category);
for ($i=0; $i < count($subcategories); $i++) {
$subcategories[$i] =
array(array('text'=>$subcategories[$i],'callback_data'=>$subcategories[$i]));
}
$decoded_subcategories = json_encode(array('inline_keyboard' => $subcategories));
$parameters =
array(
'chat_id' => $chat_id,
'message_id' => $message_id,
'reply_markup' => $decoded_subcategories
);
$telegram->editMessageReplyMarkup($parameters)
}
So basically I send everything which is requeired: message_id, chat_id, new_markup. And when I run that script I can see arrays are built fine, see the next screenshot:
And everything I got from this is false returning me from method I called, of coruse no changes in telegram bot message.
Does anyone have any ideas? Thank you for reply.
Related
There is currently 25k+ users we have in database. All users are subscribed to a common topic All.
I have two directories inside public_html. First is for API built in codeigniter. This API is used to provide data for all adnroid and iOS devices.
Second directory is for admin panel built in Laravel. We use it to upload data and also to send notification to firebase topics.
Both API and Admin Panel share same database.
If we send notification to topics which is not subscribed by much
users, there is no issue. But If I send notificaiton to a topic
which has much users It causes problems on our backend. The API
stops responding, or sometimes takes too long to respond.
Sometimes also admin panel stops responding too.
I am so confused because all the things are handled by firebase. I just make one API call.
Can anyone explain what's causing the problem?
Or any possible reason?
Update
use Kreait\Firebase\Messaging;
use Illuminate/Support/Http/Request;
trait UserTrait {
public function notify(Request $request, Messaging $messaging) {
$message_hi = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title_hi,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText_hi,
"image_url" => $request->image_url,
);
$message = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText,
"image_url" => $request->image_url,
);
$commodityIdArray = $request->cId
//to send all
if($request->notification_type == 1) {
$messaging->sendAll([
['topic' => 'All', 'data' => $message],
['topic' => 'All_hi', 'data' => $message_hi],
]);
} else {
//to send to a fourite topic subscribed by some users
//Prepare Condition for both hindi and english users
$topic_condition = "";
$topic_condition_hi = "";
foreach($commodityIdArray as $topic) {
$topic_condition .="'".$topic."' in topics && ";
$topic_condition_hi.="'".$topic."_hi' in topics &&";
}
//send notification to hindi and english topics
$messaging->sendAll([
['condition' => substr($topic_condition, 0, -3), 'data' =>
$message],
['condition' => substr($topic_condition_hi, 0, -3), 'data' =>
$message_hi],
]);
}
}
Use Queue
You have to use a Queue which set your process in queue and when one process completes, the second one starts
you can also set number of retries of your process
I'm working on a telegram bot shop via https://github.com/php-telegram-bot/core in laravel.
In this app , each Product has many images that path of them is stored on th DB.
Now I want when send details of a product , images of that shown one by one that user can navigate them via a prev and next inline keyboard. like this picture :
For that after show all products in the shop as a inline query and after use choose one of them , On Chosen inline result Command, I get a product Id and fetch first image of that from DB like this :
class ChoseninlineresultCommand extends SystemCommand
{
public function execute ()
{
$chosenInlineResult = $this->getChosenInlineResult();
$chosenInlineResultId = $product_id = $chosenInlineResult->getResultId();
$chat_id = $chosenInlineResult->getFrom()->getId();
$product = Product::findOrFail($product_id);
$picture = $product->images->first();
$keyboard = KeyboardController::showProductKeyboard($product_id, $chat_id);
$result = view('show-product', compact('product','picture'))->render();
Request::sendMessage([
'chat_id' => $chat_id,
'text' => $result,
'reply_markup' => $keyboard,
'parse_mode' => 'HTML'
]);
}
}
Also showProductKeyboard of KeyboardController is like this :
static public function showProductKeyboard ($product_id, $user_id)
{
$inlineKeyboard = new InlineKeyboard([]);
$inlineKeyboard->addRow(new InlineKeyboardButton([
'text' => ' previous picture ⬅️️',
'callback_data' => 'prev_pic'
]), new InlineKeyboardButton([
'text' => '➡️ next picture ',
'callback_data' => 'next_pic'
]));
return $inlineKeyboard;
}
And finally show-product blade is simple as :
🛍️ <b>{{$product->title}}</b>
✅ <b>{{str_limit(strip_tags($product->desc), 50)}}</b>
💵 <b>{{number_format($product->price)}}</b> dollor
Picture
Problem is that I do not know how can I implement what I want .
You can't change the product image by callback query, you can change only the text by method editMessageText https://core.telegram.org/bots/api#editmessagetext
The solution can be deleting the message and send a new message with next picture.
And you should set more data in callback_data. For example showproduct_<id next product>
I'm trying out the ActiveCollab API for my first time. I had to use StackOveflow to figure out how to get the API token since the docs don't tell me this.
Below is my code:
/* GET INTENT */
$url = 'https://my.activecollab.com/api/v1/external/login';
$fields = array(
'email' => "email#email.com",
'password' => "****"
);
$intent = curl_post_connector($url, $fields);
$intent = $intent->user->intent;
/* GET TOKEN */
$url = 'https://app.activecollab.com/my_app_id/api/v1/issue-token-intent';
$fields = array(
'intent' => $intent,
'client_name' => 'My App Name',
'client_vendor' => 'My Company Name'
);
$token = curl_post_connector($url, $fields);
$token = $token->token;
Everything above works and get's the token properly. What I find really weird is that I have to use API v1 to get this, and the docs on ActiveCollab's site don't mention any URL for API v5. It seems like this is the approach everything is taking here on StackOverflow.
Now with the token, I try to get my list of projects:
/* GET PROJECT */
$url = 'https://app.activecollab.com/my_app_id/api/v1/users';
$headers = array (
"X-Angie-AuthApiToken" => $token
);
$projects = curl_get_connector($url, $headers);
var_dump($projects);
But this does not work. There is no error returned - it instead returns an array of languages for some reason! I don't want to paste the massive json object here, so instead I'll link you to a photo of it: https://www.screencast.com/t/7p5JuFB4Gu
UPDATE:
When attempting to use the SDK, it works up until I try getting the token (which is just as far as I got without the SDK). I'm getting Server Error 500, and when looking at the logs, it says:
/home/working/public_html/ac/index.php(21): ActiveCollab\SDK\Authenticator\Cloud->issueToken(123456789)
#1 {main}
thrown in /home/working/public_html/ac/SDK/Authenticator/Cloud.php on line 115
This is line 115 of Cloud.php:
throw new InvalidArgumentException("Account #{$account_id} not loaded");
I honestly don't think I did anything wrong... there must be something wrong with my account ID.
Just for kicks, I commented out that line, and the error disappears and the page loads fine - except now I have no token...
I'm using alaouy/youtube package for one of my projects, Its working just fine, But with this method I can't use pagination! Is there any way or I've to write my own code? There is a vendor folder in my resources with pagination folder but I can't get work with it!
// List videos in a given channel, return an array of PHP objects
$videoList = Youtube::listChannelVideos('UCk1SpWNzOs4MYmr0uICEntg', 40);
I'm the creator of that package, happy that it was helpful for you and sorry that the documentation wasn't clear enough.
The listChannelVideos is based on the searchAdvanced method, so you can paginate the channel videos like this :
$params = array(
'channelId' => 'UCk1SpWNzOs4MYmr0uICEntg',
'type' => 'video',
'part' => 'id, snippet',
'maxResults' => 40);
// Make intial call. with second argument to reveal page info such as page tokens
$search = Youtube::searchAdvanced($params, true);
print_r($search); // First page results
// Check if we have a pageToken
if (isset($search['info']['nextPageToken'])) {
$params['pageToken'] = $search['info']['nextPageToken'];
}
// Make another call and repeat
$search = Youtube::searchAdvanced($params, true);
print_r($search); // Second page results
Hope this will help you!
I am trying to get to get clicks and spend data for ad campaigns.
I am currently getting all ad campaign ID's with a curl request which returns about 260 ID's.
I want to make a batch request and get the clicks, spend, start and end dates for each ID.
I have found the PHP SDK FacebookRequest() function very confusing so have been trying to make cURL requests.
Would really appreciate some help because I am just stumped at the moment. Is it best to use to FacebookRequest() function or can I continue using the cURL requests?
Not sure if I am on the right track but essentially what I have at the moment is all the campaign ID's which I group with a method, relative_url and body and then pass to a requestHandler function. The code is as follows:
$ad_account_ids = <ad_account_id>;
$ad_campaign_ids = FbAdCampaign::all()->lists('ad_campaign_id')->toArray();
foreach ($ad_campaign_ids as $key => $value) {
$ad_campaign_ids[$key] = array(
"method" => "GET",
"relative_url" => "v2.4/act_".$ad_account_ids."/adgroups",
"body" => "campaign_id=".$value."&redownload=1&bid_type=CPC&bid_info={\"clicks\":150}&creative={\"creative_id\":\"{result=create_creative:$.id}\"}&targeting={\"countries\":[\"US\"]}&name=test1"
);
$fields[] = array(
'access_token' => $access_token,
'batch' => $ad_campaign_ids[$key]
);
// $url = 'https://graph.facebook.com/v2.4/act_'.$ad_campaign_ids.'/adcampaign_groups?access_token='.$access_token;
$url = 'https://graph.facebook.com/';
$data = RequestHandler::curlRequest($url);
Ok got it.
Had to prepend the /GET data to the end of the URL to pass to the request handler.
as follows:
$url = 'https://graph.facebook.com/v2.3/act_'.$ad_account_ids.'/adcampaign_groups?access_token='.$access_token;