BotMan Version: 2.6
PHP Version: 7.3.23
Laravel Version : 7.16.1
Cache Driver: LaravelCache
i'm using botman for telegram bot.
everything is ok with botman just the conversation cache time is not working.
this is my botman Configuration code :
use BotMan\BotMan\Cache\LaravelCache;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\BotManFactory;
$config = [
// Your driver-specific configuration
"botman" => [
'conversation_cache_time' => 720 ,
'user_cache_time' => 720,
],
"telegram" => [
"token" => env('TELEGRAM_TOKEN'),
]
];
// Load the driver(s) you want to use
DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);
// Create an instance
$botman = BotManFactory::create($config, new LaravelCache());
// and other hears , fallback and conversations functions ...
every thing about the bot and conversations is fine , but the problem is about the conversation cash time
base on the conversation document we have to use drive cache to use conversations and the driver i'm using is laravelCache but i set conversation_cache_time to 720 minute but it just takes the default 30 minute.
what should i do?
thanks in advance.
From these lines in their github:
https://github.com/botman/botman/blob/79310f6e6464436aaa2d0522267b2ca00a07fda5/tests/BotManConversationTest.php#L79-L83
https://github.com/botman/botman/blob/4ec6e3f30d620cbcb73a0cf8e1dbf6b34e47f75d/src/Traits/HandlesConversations.php#L47
https://github.com/botman/botman/blob/203e7f5ef68473dd4d71ca7ee31275eae9a92745/src/BotMan.php#L238-L239
It must be like these:
$config = [
'user_cache_time' => 720,
'config' => [
'conversation_cache_time' => 720 ,
],
// Your driver-specific configuration
"telegram" => [
"token" => env('TELEGRAM_TOKEN'),
]
];
and it works.
Related
I'm writing a couple of laravel packages and I'm wondering if it is possible to have the package write to a specific log file but only for messages related to the package?
I tried making a logging.php file in the packages/myorg/mypackage/config (below) but it doesn't seem to do anything.
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
return [
'default' => env('LOG_CHANNEL', 'stack'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/mypackage.log'),
'level' => env('LOG_LEVEL', 'debug'),
]
]
];
I am using "jeroen-g/laravel-packager" to set up the packages. It appears to manually load the mypackage.config in the ServiceProvider bootForConsole
protected function bootForConsole(): void
{
// Publishing the configuration file.
$this->publishes([
mypackage.'/../config/mypackage.php' => config_path('mypackage.php'),
], 'mypackage.config');
}
I'm not sure how to add custom logging to that though. I'm still learning Laravel and I'm not quite sure what or how the main applications config/logging.php is read so I'm not quite sure how to inject a custom version for an add-on package.
EDIT:
I found a post that suggested using the following in the ServiceManager boot() method:
$this->app->make('config')->set('logging.channels.mychannel', [
/* settings */
]);
I used the package config to set a 'logging' => [ 'channels' => [ 'mychannel' => [ /* settings */ ] ] ] and could then do the same thing as above with:
$this->app->make('config')->set('logging.channels.mychannel', config('mypackage.logging.channels.mychannel');
But that still required something in the code. The next best thing I have found thus far is to change my config/logging.php to config/logging.channels.php and include something like:
return [
'mychannel' => [
'driver' => 'single',
'path' => storage_path('logs/mypackage.log'),
'level' => env('LOG_LEVEL', 'debug'),
]
];
Then in the service provider register() method add:
$this->mergeConfigFrom(__DIR__ . '/../config/logging.channels.php', 'logging.channels');
I tried doing it from the original 'logging.php' with channels array nested in a 'logging' key, but array_merge doesn't appear to merge the nested elements so my channel never showed up in logging.channels.
I'm not sure if this is ideal, however. I'd still like to know if there is a 'better' or best practices way of adding custom package logging parameters and whether there is a need to publish it in any way (and how).
I am building an integration between my Laravel application and Amazon Personalize using:
aws/aws-sdk-php
Everything goes ok, but when I look on how to update the datasets with new Users, interactions and items, I couldn't find the right method/approach to do this, or if it is even possible.
I have created the Event Tracker but I can't find how to replicate this Python code into PHP:
# Configure Properties:
event = {
"itemId": str(ITEM_ID),
}
event_json = json.dumps(event)
# Make Call
personalize_events.put_events(
trackingId = TRACKING_ID,
userId= USER_ID,
sessionId = session_ID,
eventList = [{
'sentAt': int(time.time()),
'eventType': 'EVENT_TYPE',
'properties': event_json
}]
The code above is a portion extracted from here https://github.com/aws-samples/amazon-personalize-samples/blob/master/getting_started/notebooks/1.Building_Your_First_Campaign.ipynb
That would be for tracking new events:
https://docs.aws.amazon.com/personalize/latest/dg/API_UBS_PutEvents.html
If there is a chance to avoid executing an extra Python script better, if not I will go for that option.
Thanks in advance!
I found that I need to use the PersonalizeEventsClient instead of PersonalizeClient for this purpose, as stated here:
https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-personalize-events-2018-03-22.html#putevents
The link is part of the AWS Personalize documentation, I missed that previously, there they explain how to PutEvents, Items and Users using the AWS SDK PHP, for example:
$client = AWS::createClient('personalizeevents');
$result = $client->putEvents([
'eventList' => [ // REQUIRED
[
'eventId' => '<string>',
'eventType' => '<string>', // REQUIRED
'eventValue' => <float>,
'impression' => ['<string>', ...],
'itemId' => '<string>',
'properties' => '<string>',
'recommendationId' => '<string>',
'sentAt' => <integer || string || DateTime>, // REQUIRED
],
// ...
],
'sessionId' => '<string>', // REQUIRED
'trackingId' => '<string>', // REQUIRED
'userId' => '<string>',
]);
I am also using this service provider for Laravel:
https://github.com/aws/aws-sdk-php-laravel
i have already installed the laravel-ffmpeg via composer in my project
composer require pbmedia/laravel-ffmpeg
then i added class to config/app.php file as documentation says
// config/app.php
'providers' => [
...
ProtoneMedia\LaravelFFMpeg\Support\ServiceProvider::class,
...
];
'aliases' => [
...
'FFMpeg' => ProtoneMedia\LaravelFFMpeg\Support\FFMpeg::class
...
];
then publish this config file
php artisan vendor:publish --provider="ProtoneMedia\LaravelFFMpeg\Support\ServiceProvider"
now my question is to use this package in my project, how should i use this into my controller
i saw many post and ques regarding this and i get these
use FFMpeg;
use FFMpeg\FFMpeg;
use Pbmedia\LaravelFFMpeg\FFMpeg;
use ProtoneMedia\LaravelFFMpeg\FFMpeg;
.
.
.
which one is correct, my goal is to trim a video, but which one works for that i am so confused
//config/laravel-ffmpeg.php
<?php
return [
'ffmpeg' => [
'binaries' => env('FFMPEG_BINARIES', 'ffmpeg'),
'threads' => 12,
],
'ffprobe' => [
'binaries' => env('FFPROBE_BINARIES', 'ffprobe'),
],
'timeout' => 3600,
'enable_logging' => true,
'set_command_and_error_output_on_exception' => false,
];
please help me out, thanks in advance
Use below code in your controller above class
use FFMpeg;
use FFMpeg\Coordinate\Dimension;
use FFMpeg\Format\Video\X264;
Open file using FFMpeg in your controller method
$media = FFMpeg::open($file_path);
I am trying to do something very similar to this post - Dynamic database connection symfony2 - but with Silex.
I have successfully setup my base database and the one I want to connect to dynamically.
database:
base:
driver: pdo_sqlite
path: database/dev.sqlite
website:
driver: pdo_sqlite
path: ~
The above is read into $dbs_options and then the following is used to configure this:
$app -> register(new DoctrineServiceProvider, ['dbs.options' => $dbs_options]);
// configure the ORM identities
$app -> register(new DoctrineOrmServiceProvider, [
'orm.proxies_dir' => Utils::joinPaths($app -> config -> appRoot, 'running', 'proxies'),
'orm.em.options' => [
'mappings' => $mappings
]
]
);
// set up multiple entity managers and assign the base connection as default
$app['orm.ems.default'] = 'basedb';
$app['orm.ems.options'] = [
'basedb' => [
'connection' => 'base',
'mappings' => $app['orm.em.options']['mappings']
],
'websitedb' => [
'connection' => 'website',
'mappings' => $app['orm.em.options']['mappings']
]
];
In my before event I am able to successfully interrogate the basedb to get the name of the website database that I want to connect to.
This is where I am stuck, I do not know and am not able to find how to reconfigure the database connection in Silex. Has anyone done this at all?
I did not have such a request in Silex, but you can always use
$conn = Doctrine\DBAL\DriverManager::getConnection($params, $config);
to create connection to database
I am trying to use the Craft CMS Element API. Due to an older version of PHP I am using version 1 (there is a version 1 branch).
Per the installation instructions I:
1) Uploaded the elementapi/ folder to my craft/plugins/ folder:
2) Went to Settings > Plugins from my Craft control panel and enabled the Element API plugin:
I then followed the setup instructions and created a new elementapi.php file within my craft/config/ folder:
I currently just have the following in my elementapi.php file:
<?php
namespace Craft;
return [
'endpoints' => [
'api/news.json' => [
'elementType' => 'Entry',
'criteria' => ['section' => 'news'],
'transformer' => function(EntryModel $entry) {
return [
'title' => $entry->title,
'url' => $entry->url,
'jsonUrl' => UrlHelper::getUrl("news/{$entry->id}.json"),
'summary' => $entry->summary,
];
},
],
]
];
I tried navigating to http://myUrl/api/news.json, but received the following error: The requested URL /api/news.json was not found on this server.
Any ideas what I may be missing or how I can debug this?