Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/badfarm/zanzara/wiki#conversations not working #86

Open
festars opened this issue Jun 3, 2023 · 5 comments
Open

Comments

@festars
Copy link

festars commented Jun 3, 2023

The function isnt working, whats the issue

@awohsen
Copy link
Contributor

awohsen commented Jun 12, 2023

Hi, are you using webhook? Please show us your code

@festars
Copy link
Author

festars commented Aug 8, 2023

How do i set or configure the cache?

@awohsen
Copy link
Contributor

awohsen commented Aug 8, 2023

How do i set or configure the cache?

@festars default cache adaptor is memory cache and when your script exits it will be gone, you can use other adaptors as long as it implements React\Cache\CacheInterface it should work, use this method to configure it:
https://github.com/badfarm/zanzara/blob/develop/src/Zanzara/Config.php#L441-L455

like:

$config = new Zanzara\Config();
$config->setCache(new ArrayCache());

Adaptors:
https://github.com/WyriHaximus/reactphp-cache-redis
https://github.com/WyriHaximus/reactphp-cache-filesystem

@festars
Copy link
Author

festars commented Aug 9, 2023

Cache with long polling seems to work ok

Problem i have is with webhook, can you kindly show a working example

@awohsen
Copy link
Contributor

awohsen commented Nov 8, 2023

Here's working example:
copy https://github.com/reactphp/cache/blob/1.x/src/ArrayCache.php into your project files,
change $data & $expires properties to public:

public $data = array();
public $expires = array();

then in your main script:

$cache = new ArrayCache();
if (file_exists(__DIR__.'/.cache'))
    if (($_cache = json_decode(file_get_contents(__DIR__.'/.cache'),1)) !== null){
        if (isset($_cache['data'])) $cache->data = $_cache['data'];
        if (isset($_cache['expires'])) $cache->expires = $_cache['expires'];
    }


$config = new \Zanzara\Config();
$config->setCache($cache);
$config->setCacheTtl(null); //persistent

$bot = new Zanzara($_ENV['BOT_TOKEN'], $config);

/**
 * Bot logic here
 */

$bot->run();

$_cache = [];
$_cache['data'] = $cache->data;
$_cache['expires'] = $cache->expires;
file_put_contents(__DIR__.'/.cache',json_encode($_cache, JSON_PRETTY_PRINT));

or even if you want long polling with persistent ArrayCache:

$bot->getLoop()->addPeriodicTimer(5, function () use ($cache){
    $_cache = [];
    $_cache['data'] = $cache->data;
    $_cache['expires'] = $cache->expires;
    file_put_contents(__DIR__.'/.cache',json_encode($_cache, JSON_PRETTY_PRINT));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants