Download photos from Telegram channel history without file_id - api

I want to download all photo from channel. Try to use https://github.com/danog/MadelineProto to get channel message history:
$MadelineProto->messages->getHistory([
'peer' => "-100xxxxxx",
'offset_id' => 0,
'offset_date' => 0,
'add_offset' => 0,
'limit' => 25,
'max_id' => 1000,
'min_id' => 0,
'hash' => 1,
]);
As a result I get an array of messages with media:
array(13) {
["_"] => string(7) "message"
["out"] => bool(false)
["mentioned"] => bool(false)
["media_unread"] => bool(false)
["silent"] => bool(false)
["post"] => bool(false)
["id"] => int(38)
["from_id"] => int(500100000)
["to_id"] => array(2) {
["_"] =>string(11) "peerChannel"
["channel_id"] =>int(1369700000)
}
["date"] => int(1520150410)
["message"] => string(0) ""
["media"] => array(2) {
["_"] =>string(17) "messageMediaPhoto"
["photo"] =>array(6) {
["_"] => string(5) "photo"
["has_stickers"] => bool(false)
["id"] => int(5251753100000000000)
["access_hash"] => int(-6118957000000000000)
["date"] => int(1520150405)
["sizes"] => array(4) {
[0] =>array(6) {
["_"] => string(9) "photoSize"
["type"] => string(1) "s"
["location"] => array(5) {
["_"] =>string(12) "fileLocation"
["dc_id"] =>int(2)
["volume_id"] =>int(235100000)
["local_id"] =>int(250000)
["secret"] =>int(5193339136300000000)
}
["w"] => int(90)
["h"] => int(67)
["size"] => int(1078)
}
....
Now I want to download this file and didnt known how do it. Method https://core.telegram.org/bots/api#getfile request file_id but I havent it.
Message history only give me this photo parameters:
id
access_hash
dc_id
volume_id
local_id
secret
How can I get file_id or generate it from available data?
Or how can I download photo from channel history by another way?

MadelineProto has undocumented functions like download_to_file or download_to_dir.
$MadelineProto->download_to_dir($message['media'], $pathtodir)

Related

Issue with post API curl library codeigniter 3

I use this library:
https://github.com/php-curl-class/php-curl-class
Base on documentation I write function for post order:
public function create_order()
{
$curl = new Curl();
$curl->setHeader('CustomerId', 'xxxxxxx');
$curl->setHeader('UserName', 'xxxxxxxxxx');
$curl->setHeader('ActionApiKey', 'xxxxxxxxxxxxxxx');
$order = array(
"createEmpty" => false,
"header" => array(
"comment" => "string",
"country" => "Polska",
"currency" => "PLN",
"isFileRequired" => true,
"actionCustomerId" => "81790",
"payer" => "EndCustomer",
"paymentType" => "CashOnDelivery",
"partnerOrderId" => "81790",
"deliveryAddresType" => "EndCustomer",
"cashOnDeliveryType" => "FullRate",
"cashOnDelivery" => 155,
"deliveryCompanyName" => "TEST API ORDER DO NOT SHIP",
"deliveryCity" => "Poznań",
"deliveryPhone" => "xxxxxxx",
"deliveryStreet" => "xxxxxxxxxx",
"deliveryZipCode" => "xxxxxxx"
),
"items" => array(
array(
"actionProductId" => "MULLOGKAM0087",
"quantity" => 1,
"price" => 122,
"backOrderType" => "BackOrder"
)
)
);
$curl->setHeader('Content-Type', 'application/json');
$curl->post('xxxxxxxxxxxxxxxxxxxxx/v2/Order', json_encode($order));
if ($curl->error) {
echo 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
} else {
echo 'Respone: ' . $curl->response;
}
}
After run controller, I get white page (I not get any error) but order not created. I test in Insomia API client and with this headers and data order created sucess.
Im not sure I correct post headers also with order data ?

Cakephp 4 save delete auto_increment

I'm doing cakephp4 controller test with phpUnit but when I call save my id auto_increment disapear.
My table before save():
Image before save
The test:
public function testAdd(): void
{
$this->session([
'Auth' => [
'id' => 1,
'DNI_CIF' => '22175395Z',
'name' => 'Prueba',
'lastname' => 'Prueba Prueba',
'username' => 'Pruebatesting',
'password' => 'prueba',
'email' => 'prueba#gmail.com',
'phone' => '639087621',
'role' => 'admin',
'addres_id' => 1
]
]);
$this->get('animal/add');
$this->assertResponseOk();
$data=[
'id' => 1,
'name' => 'AñadirAnimal',
'image' => '',
'specie' => 'dog',
'chip' => 'no',
'sex' => 'intact_male',
'race' => 'cat',
'age' => 1,
'information' => 'Es un animal.',
'state' => 'sick',
'animal_shelter' => [
'id' => 1,
'start_date' => '2022-11-03 10:47:38',
'end_date' => '2022-11-03 10:47:38',
'user_id' => 1,
'animal_id' => 1
]
];
$this->enableCsrfToken();
$this->post('animal/add',$data);
$this->assertResponseOk();
}
The controller:
public function add()
{
$animal = $this->Animal->newEmptyEntity();
if ($this->request->is('post')) {
$animal = $this->Animal->patchEntity($animal, $this->request->getData());
if(!$animal->getErrors){
$image = $this->request->getData('image_file');
if($image !=NULL){
$name = $image->getClientFilename();
}
if( !is_dir(WWW_ROOT.'img'.DS.'animal-img') ){
mkdir(WWW_ROOT.'img'.DS.'animal-img',0775);
if($name){
$targetPath = WWW_ROOT.'img'.DS.'animal-img'.DS.$name;
$image->moveTo($targetPath);
$animal->image = 'animal-img/'.$name;
}
}
if ($this->Animal->save($animal)) {
$this->Flash->success(__('El animal se ha añadido.'));
return $this->redirect(['action' => 'index']);
}
}
$this->Flash->error(__('El animal no se ha podido añadir, por favor intentalo de nuevo'));
}
$allUsers = $this->getTableLocator()->get('User');
$user = $allUsers->find('list', ['limit' => 200])->all();
$this->set(compact('animal','user'));
}
My table after:
Image after save
The error:
1) App\Test\TestCase\Controller\AnimalControllerTest::testAdd
Possibly related to PDOException: "SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value"
…
Failed asserting that 500 is between 200 and 204.
I don't know why this is happening or how to know the reason. In the app the controller works fine. Data in the app:
Data in app
Data in test:
Data in test
I hope someone can help me, I don't know what to try anymore or how to know where the problem is...
I tried to look at the data but it doesn't apear to have any errors so I don't know where the error can be.
It was that the sql file used in the bootstrap didn't have the autoincrement value.

Laravel queue:work not behaving same as queue:listen

<?php
namespace App\Notifications;
use Illuminate\Notifications\Channels\MailChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Config;
class DynamicEmailChannel extends MailChannel
{
public function send($notifiable, Notification $notification)
{
$service = $notification->service;
$customConfig = [];
$from = [];
if ($service->sender_email && $service->sender_password) {
$customConfig = [
'transport' => 'smtp',
'host' => 'smtp.googlemail.com',
'port' => 587,
'encryption' => 'tls',
'username' => $service->sender_email,
'password' => $service->sender_password,
'timeout' => null,
'auth_mode' => null,
];
$from = [
'address' => $service->sender_email,
'name' => $service->title
];
} else {
$customConfig = [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
];
$from = [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example')
];
}
Config::set('mail.mailers.smtp', $customConfig);
Config::set('mail.from', $from);
app()->forgetInstance('mail.manager');
parent::send($notifiable, $notification);
}
}
this program works when run through php artisan queue:listen but the app()->forgetInstance('mail.manager'); runs only once when run through php artisan queue:work. How do i make it behave as with queue:listen?
I am trying to send mail notifications through credentials saved in database.
If i am not wrong, if i delete the 'mail.manager' serviceInstance, it will create new one when called with latest config. it works the same way for queue:listen but not for queue:work. what am i missing, or not understanding here.
After doing some digging replacing app()->forgetInstance('mail.manager'); with Mail::purge('smtp'); solved the issue.

Shopware 6 Product API doesn't set the buying price

In Shopware 6 I still try to get the product into the System using the API.
I now get a product, but it has no price, despite the fact, that I inserted it.
That actually results in a product without a price and stops the backend from loading the products, so I have to manually change the price using the export, edit, and then import method.
The product object gets encoded with json_encode as well before sending that as a request to the API.
I can't seem to find out what's wrong with the following code:
$price = [
"currencyId" => "b7d2554b0ce847cd82f3ac9bd1c0dfca",
"net" => $net,
"gross" => $gross,
"linked" => false
];
$price = json_encode($price);
$product = [
"id" => str_replace("-","", $productId),
"productId" => str_replace("-","", $productId),
"name" => $name,
"taxId" => $taxId,
"productNumber" => $productNumber,
"minPurchase" => $minPurchase,
"price" => $price,
"purchasePrice" => $purchasePrice,
"stock" => $stock,
"images" => $images,
"atributes" => $atributes,
"categoryId" => "7997459a37f94a75a14d7cbd872a926f"
];
I had to write the code like this:
$product = [
"id" => str_replace("-","", $productId),
"productId" => str_replace("-","", $productId),
"parentId" =>str_replace("-","", "4307a3d9afee4b46b3da1a8fc6230db5"),
"name" => $name,
"taxId" => $taxId,
"productNumber" => $productNumber,
"minPurchase" => $minPurchase,
"price" => [[
"currencyId" => "b7d2554b0ce847cd82f3ac9bd1c0dfca",
"net" => $net,
"gross" => $price,
"linked" => true
]],
"purchasePrice" => $purchasePrice,
"stock" => $stock,
"description" => $description,
"images" => $images,
"atributes" => $atributes,
"categoryId" => "7997459a37f94a75a14d7cbd872a926f"
];

Laravel 5.5 BroadcastException with Pusher

I have create the chat application in laravel with Brodecast+Vue so when trying to my test broadcast class its getting error "BroadcastException in PusherBroadcaster.php (line 106)" I have double checked all configurations and api authentications are correct. but getting error and pusher debug console do not display and request.
driver :
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'ap1',
'encrypted' => true
],
],
event :
public $message;
public $user;
public function __construct($message, User $user)
{
$this->message = $message;
$this->user = $user;
}
test function :
public function test()
{
$user = User::find(Auth::id());
event(new ChatEvent('Hello pusher', $user));
return response('done');
}
i think you need to make encrypted = false.
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'ap1',
'encrypted' => false
],
],