taddy/taddy-sdk
最新稳定版本:1.1.11
Composer 安装命令:
composer require taddy/taddy-sdk
包简介
Taddy PHP SDK
README 文档
README
composer require taddy/taddy-sdk
Initialize Taddy
use Taddy\Sdk\Taddy; $taddy = new Taddy(pubId: 'bot-xxxxxxxxxxxxxx', new TaddyOptions( token: '123456780:yyyyyyyyyyyyyyyyyy', // Your bot's token ));
Define User with all data you have
use Taddy\Sdk\Dto\User as TaddyUser; $user = TaddyUser::factory($tgUserId) ->withUsername($tgUsername) ->withFirstName($tgFirstName) // other stuff ;
Start event
Handle /start command to detect incoming users (basic integration)
$taddy->start( user: $user, // User DTO start: $startMessage // text from update with /start command );
Ads Service
Initialize Ads Service
$ads = $taddy->ads();
Automatically show ads
// Retrieve ad for $user $ad = $ads->getAd($user); // Ad exists, showtime! if ($ad) { $ads->show($ad, $user); }
Manual show ads
// Retrieve ad for $user $ad = $ads->getAd($user); // Ad exists, showtime! if ($ad) { // show $ad myShowAdFuncation($ad); // your custom method // send imoressions event $ads->impressions($user, $ad->id); // show ad delay 15 sec. sleep(15); // hide $ad (delete message) myHideAdFuncation($ad); // your custom method }
Exchange Service
Initialize Exchange Service
$exchange = $taddy->exchange();
Get tasks list (feed) to display
This method returns array of ExchangeFeedItem DTO with id, title, description, image, type and link fields.
You need to display it how you want.
$feed = $exchange->getFeed( user: $user, // User DTO limit: 4, // limit tasks count imageFormat: 'png', // png, webp, jpg autoImpressions: false, // automatically send impressions event );
Send impressions event
If you are not used autoImpressions in previous step, you should use this call to send impressions event manually
// send impressions event manually (after successful show) $exchange->impressionsEvent( user: $user, // User DTO items: $feed, // showed items array );
Check exchange
You track if exchange completed using webhooks or calling this method
// send impressions event manually (after successful show) $exchange->check( user: $user, // User DTO item: $item, // ExchangeFeedItem DTO or item id );
Custom events (optional)
// send custom event $taddy->customEvent( user: $user, // User DTO event: 'custom1', // custom event: custom1 ... custom4 value: 1.23, // Value (optional) currency: Currency::USD, // value currency (optional) once: false, // one-time event registration (optional) );
See also
统计信息
- 总下载量: 835
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-08