Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

🚀 Pull Request

📋 Description

Introduces project-owned types (tgbot_api namespace) using raw pointers to decouple from tgbot-cpp library's type system. The TgBot API now exposes only project types while hiding tgbot-cpp implementation behind a bidirectional translation layer.

Architecture Changes:

  • Type System (src/include/api/types/): Complete Telegram type definitions (User, Chat, Message, Media types, Reply/Input types) using raw pointers instead of shared_ptr
  • Message Integration: Merged MessageExt parsing capabilities directly into tgbot_api::Message - single unified type with raw pointer members
  • Translation Layer (TgBotTranslator): Bidirectional conversions between TgBot:: and tgbot_api:: types, allocating with new instead of std::make_shared
  • API Surface: Updated TgBotApi, AuthContext, CommandModule, Utils to use only project types
  • TgBotApiImpl: Updated to translate between TgBot::Message and tgbot_api::Message, managing memory lifecycle with explicit delete

Pointer Convention:

All project types use raw pointers (T*) instead of std::shared_ptr<T>:

// Type definitions
class User {
   public:
    using Ptr = User*;  // Raw pointer, not shared_ptr
};

class Message {
   public:
    using Ptr = Message*;
    User::Ptr from{nullptr};  // Raw pointer fields
    Chat::Ptr chat{nullptr};
};

Command Handler Migration:

// Before
#include <api/MessageExt.hpp>
void handler(TgBotApi::Ptr api, MessageExt* message, ...) {
    auto chat = message->get<MessageAttrs::Chat>();
}

// After  
#include <api/types/Message.hpp>
void handler(TgBotApi::Ptr api, tgbot_api::Message* message, ...) {
    auto chat = message->get<tgbot_api::MessageAttrs::Chat>(); // Same API, raw pointers
}

Memory Management:

  • Translator allocates with new, returns raw pointers
  • TgBotApiImpl::commandHandler manages message lifetime with explicit delete
  • Command modules receive raw pointer but should not delete it (managed by caller)

Benefits:

  • TgBotApi interface stable across tgbot-cpp updates
  • Type changes isolated to TgBotTranslator
  • Consistent with project's raw pointer conventions (matches existing MessageExt pattern)
  • No reference counting overhead
  • Foundation for library migration if needed

✅ Checklist

  • I ran cmake + make/ninja and verified the project builds.
  • I tested the changes with a live Telegram bot or mock unit tests.
  • I updated/add relevant documentation or inline comments.
  • I verified that the change does not break existing functionality.
  • I followed the project's code style (e.g. clang-format, naming conventions).

🧪 Test Plan

Completed Work:

  • ✅ Project type infrastructure with raw pointers
  • ✅ Translation layer with new allocation
  • ✅ TgBotApiImpl updated to use translator and manage memory
  • ✅ All API headers updated to use project types

Remaining Work:

  • Update individual command modules (include path changes from MessageExt to tgbot_api::Message)
  • Update socket components, global handlers
  • Remove legacy MessageExt files
  • Build and test with dependencies installed

See DEPENDENCY_EJECTION.md for complete architecture documentation.

📌 Related Issues or PRs

📝 Notes

Current State: Type infrastructure, translation layer, and TgBotApiImpl implementation complete. Uses raw pointers throughout for consistency with project conventions. Memory is managed explicitly with new/delete in the translation layer and command handler.

Memory Safety: Callers of translation functions are responsible for deleting returned pointers. TgBotApiImpl's commandHandler manages the lifecycle properly with early returns and cleanup after execution.

TgBot::InlineQueryResult and EventBroadcaster: Intentionally kept as TgBot types - internal implementation details not exposed through public API.

Original prompt

create dependency ejection from tgbot-cpp in overall code. As in. introduce project-only telegram object types in src/include/api/types and src/api/types, move all code to that, and use tgbotapi pointer to hide the real implementation. And add a translation layer with the project type-method and the tgbot-cpp methods, types. Remove MessageExt during the process and transform it to src/api/types/Message


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits December 30, 2025 11:45
Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
…types

Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement dependency ejection from tgbot-cpp Eject dependency on tgbot-cpp types through translation layer Dec 30, 2025
Copilot AI requested a review from Royna2544 December 30, 2025 11:54
@Royna2544
Copy link
Owner

@copilot continue the work

Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 30, 2025

@copilot continue the work

Updated all project types to use raw pointers instead of shared_ptr per project conventions (commit cfa8f74). All Ptr typedefs changed from std::shared_ptr<T> to T*, and TgBotTranslator now allocates with new instead of std::make_shared.

Continuing with Phase 4: updating TgBotApiImpl to use the translation layer.

Co-authored-by: Royna2544 <69458352+Royna2544@users.noreply.github.com>
Copilot AI changed the title Eject dependency on tgbot-cpp types through translation layer Eject dependency on tgbot-cpp types through translation layer with raw pointers Dec 30, 2025
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

Successfully merging this pull request may close these issues.

2 participants