Skip to content

Commit b73ad4a

Browse files
Connect platform implementations to real Zig FFI calls
- Added Ada FFI bindings for Discord (trigger-ffi-discord.ads) - Added Ada FFI bindings for Telegram (trigger-ffi-telegram.ads) - Added Ada FFI bindings for Twitter (trigger-ffi-twitter.ads) - Added parent FFI package (trigger-ffi.ads) - Updated Discord platform implementation to use FFI for Connect, Disconnect, Ping - Updated Telegram platform implementation to use FFI for Connect, Disconnect, Ping, Is_Authorized - Updated Twitter platform implementation to use FFI for Connect, Disconnect, Ping - Updated trigger.gpr to include new FFI binding files - Renamed discord.ads to trigger-ffi-discord.ads for proper Ada package naming Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
1 parent 11034f1 commit b73ad4a

11 files changed

Lines changed: 263 additions & 22 deletions
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212

1313
package Trigger.FFI.Discord is
1414

15+
-- Opaque type for void pointers from C
16+
type Void_Ptr is access all Integer;
17+
1518
-- Discord client handle (opaque pointer from Zig)
16-
type Discord_Client_Ptr is access all void;
19+
type Discord_Client_Ptr is access all Integer;
1720

1821
-- Discord message handle
19-
type Discord_Message_Ptr is access all void;
22+
type Discord_Message_Ptr is access all Integer;
2023

2124
-- Discord user handle
22-
type Discord_User_Ptr is access all void;
25+
type Discord_User_Ptr is access all Integer;
2326

2427
-- Discord guild (server) handle
25-
type Discord_Guild_Ptr is access all void;
28+
type Discord_Guild_Ptr is access all Integer;
2629

2730
-- Discord Snowflake type (64-bit ID)
2831
type Snowflake is mod 2**64;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
-- Trigger - Telegram FFI Bindings Specification
2+
--
3+
-- Ada bindings for Telegram API via Zig FFI (unified-hexadeca-api)
4+
--
5+
-- This package provides the interface for calling Telegram functions
6+
-- implemented in Zig through C-exported symbols.
7+
--
8+
-- Author: hyperpolymath
9+
-- Architecture: Ada/SPARK <- Idris2 <- Zig (FFI)
10+
-- License: MPL-2.0
11+
-- SPDX-License-Identifier: MPL-2.0
12+
13+
package Trigger.FFI.Telegram is
14+
15+
-- Telegram client handle (opaque pointer from Zig)
16+
type Telegram_Client_Ptr is access all Integer;
17+
18+
-- Telegram message handle
19+
type Telegram_Message_Ptr is access all Integer;
20+
21+
-- Telegram user handle
22+
type Telegram_User_Ptr is access all Integer;
23+
24+
-- Telegram chat/channel handle
25+
type Telegram_Chat_Ptr is access all Integer;
26+
27+
-- Maximum string lengths
28+
Max_Phone_Length : constant := 20;
29+
Max_Username_Length : constant := 64;
30+
Max_Message_Length : constant := 4096;
31+
32+
-- Create a Telegram client
33+
function Create_Client (
34+
Api_Id : Integer;
35+
Api_Hash : String;
36+
Session_Dir : String
37+
) return Telegram_Client_Ptr
38+
with Import, Convention => C, External_Name => "create_telegram_client";
39+
40+
-- Destroy a Telegram client
41+
procedure Destroy_Client (Client : Telegram_Client_Ptr)
42+
with Import, Convention => C, External_Name => "destroy_telegram_client";
43+
44+
-- Connect to Telegram
45+
function Connect (Client : Telegram_Client_Ptr) return Integer
46+
with Import, Convention => C, External_Name => "telegram_client_connect";
47+
48+
-- Disconnect from Telegram
49+
procedure Disconnect (Client : Telegram_Client_Ptr)
50+
with Import, Convention => C, External_Name => "telegram_client_disconnect";
51+
52+
-- Check if connected
53+
function Is_Connected (Client : Telegram_Client_Ptr) return Integer
54+
with Import, Convention => C, External_Name => "telegram_client_is_connected";
55+
56+
-- Check if authorized
57+
function Is_Authorized (Client : Telegram_Client_Ptr) return Integer
58+
with Import, Convention => C, External_Name => "telegram_client_is_authorized";
59+
60+
-- Get current user
61+
function Get_Me (Client : Telegram_Client_Ptr) return Telegram_User_Ptr
62+
with Import, Convention => C, External_Name => "telegram_client_get_me";
63+
64+
-- Get messages from a chat/channel
65+
function Get_Messages (
66+
Client : Telegram_Client_Ptr;
67+
Chat_Identifier : String;
68+
Limit : Integer
69+
) return Telegram_Message_Ptr
70+
with Import, Convention => C, External_Name => "telegram_client_get_messages";
71+
72+
-- Report a message
73+
procedure Report_Message (
74+
Client : Telegram_Client_Ptr;
75+
Chat_Identifier : String;
76+
Message_Id : Integer;
77+
Reason : Integer
78+
)
79+
with Import, Convention => C, External_Name => "telegram_client_report_message";
80+
81+
-- Send a message
82+
function Send_Message (
83+
Client : Telegram_Client_Ptr;
84+
Chat_Identifier : String;
85+
Content : String
86+
) return Telegram_Message_Ptr
87+
with Import, Convention => C, External_Name => "telegram_client_send_message";
88+
89+
-- Ping the Telegram API
90+
function Ping (Client : Telegram_Client_Ptr) return Integer
91+
with Import, Convention => C, External_Name => "telegram_client_ping";
92+
93+
end Trigger.FFI.Telegram;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
-- Trigger - Twitter/X FFI Bindings Specification
2+
--
3+
-- Ada bindings for Twitter/X API via Zig FFI (unified-hexadeca-api)
4+
--
5+
-- This package provides the interface for calling Twitter/X functions
6+
-- implemented in Zig through C-exported symbols.
7+
--
8+
-- Author: hyperpolymath
9+
-- Architecture: Ada/SPARK <- Idris2 <- Zig (FFI)
10+
-- License: MPL-2.0
11+
-- SPDX-License-Identifier: MPL-2.0
12+
13+
package Trigger.FFI.Twitter is
14+
15+
-- Twitter client handle (opaque pointer from Zig)
16+
type Twitter_Client_Ptr is access all Integer;
17+
18+
-- Twitter message/tweet handle
19+
type Twitter_Tweet_Ptr is access all Integer;
20+
21+
-- Twitter user handle
22+
type Twitter_User_Ptr is access all Integer;
23+
24+
-- Maximum string lengths
25+
Max_Username_Length : constant := 15; -- X/Twitter username limit
26+
Max_Tweet_Length : constant := 280; -- X/Twitter tweet character limit
27+
Max_DM_Length : constant := 10000; -- Direct message limit
28+
29+
-- Twitter Snowflake type (64-bit ID)
30+
type Snowflake is mod 2**64;
31+
32+
-- Create a Twitter client
33+
function Create_Client (
34+
Bearer_Token : String;
35+
Api_Key : String;
36+
Api_Secret : String
37+
) return Twitter_Client_Ptr
38+
with Import, Convention => C, External_Name => "create_twitter_client";
39+
40+
-- Destroy a Twitter client
41+
procedure Destroy_Client (Client : Twitter_Client_Ptr)
42+
with Import, Convention => C, External_Name => "destroy_twitter_client";
43+
44+
-- Get current user
45+
function Get_Me (Client : Twitter_Client_Ptr) return Twitter_User_Ptr
46+
with Import, Convention => C, External_Name => "twitter_client_get_me";
47+
48+
-- Get tweets from a user timeline
49+
function Get_Tweets (
50+
Client : Twitter_Client_Ptr;
51+
User_Id : String;
52+
Limit : Integer
53+
) return Twitter_Tweet_Ptr
54+
with Import, Convention => C, External_Name => "twitter_client_get_tweets";
55+
56+
-- Get direct messages
57+
function Get_DMs (
58+
Client : Twitter_Client_Ptr;
59+
Limit : Integer
60+
) return Twitter_Tweet_Ptr
61+
with Import, Convention => C, External_Name => "twitter_client_get_dms";
62+
63+
-- Report a tweet
64+
procedure Report_Tweet (
65+
Client : Twitter_Client_Ptr;
66+
Tweet_Id : Snowflake;
67+
Reason : Integer
68+
)
69+
with Import, Convention => C, External_Name => "twitter_client_report_tweet";
70+
71+
-- Report a user
72+
procedure Report_User (
73+
Client : Twitter_Client_Ptr;
74+
User_Id : String;
75+
Reason : Integer
76+
)
77+
with Import, Convention => C, External_Name => "twitter_client_report_user";
78+
79+
-- Send a tweet
80+
function Send_Tweet (
81+
Client : Twitter_Client_Ptr;
82+
Content : String
83+
) return Twitter_Tweet_Ptr
84+
with Import, Convention => C, External_Name => "twitter_client_send_tweet";
85+
86+
-- Ping the Twitter API
87+
function Ping (Client : Twitter_Client_Ptr) return Integer
88+
with Import, Convention => C, External_Name => "twitter_client_ping";
89+
90+
end Trigger.FFI.Twitter;

‎src/trigger/ffi/trigger-ffi.ads‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Trigger - FFI Package Specification
2+
--
3+
-- Parent package for all FFI bindings (Discord, Telegram, Twitter)
4+
--
5+
-- Author: hyperpolymath
6+
-- Architecture: Ada/SPARK <- Idris2 <- Zig (FFI)
7+
-- License: MPL-2.0
8+
-- SPDX-License-Identifier: MPL-2.0
9+
10+
package Trigger.FFI is
11+
end Trigger.FFI;

‎src/trigger/platforms/discord/discord-platform.adb‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
with Platform_Types;
1515
with Platform_Interface;
16+
with Trigger.FFI.Discord;
1617

1718
package body Discord_Platform is
1819

@@ -23,6 +24,7 @@ package body Discord_Platform is
2324
return Result : constant Platform_Implementation do
2425
Result.Token := Token;
2526
Result.Base_Url := Base_Url;
27+
Result.Client := Trigger.FFI.Discord.Create_Client (Token);
2628
end return;
2729
end Init;
2830

@@ -76,13 +78,19 @@ package body Discord_Platform is
7678
function Connect (This : Platform_Implementation; Session : Session_Type)
7779
return Boolean is
7880
begin
79-
return True;
81+
if This.Client /= null then
82+
return Trigger.FFI.Discord.Ping (This.Client) = 1;
83+
end if;
84+
return False;
8085
end Connect;
8186

8287
overriding
8388
procedure Disconnect (This : Platform_Implementation; Session : in out Session_Type) is
8489
begin
85-
null;
90+
if This.Client /= null then
91+
Trigger.FFI.Discord.Destroy_Client (This.Client);
92+
This.Client := null;
93+
end if;
8694
end Disconnect;
8795

8896
overriding
@@ -219,8 +227,10 @@ package body Discord_Platform is
219227
overriding
220228
function Ping (This : Platform_Implementation) return Boolean is
221229
begin
222-
-- Discord has higher rate limits
223-
return True;
230+
if This.Client /= null then
231+
return Trigger.FFI.Discord.Ping (This.Client) = 1;
232+
end if;
233+
return False;
224234
end Ping;
225235

226236
overriding

‎src/trigger/platforms/discord/discord-platform.ads‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
with Platform_Types;
1515
with Platform_Interface;
16+
with Trigger.FFI.Discord;
1617

1718
package Discord_Platform is
1819

@@ -24,6 +25,7 @@ package Discord_Platform is
2425
private
2526
Token : String(1..256);
2627
Base_Url : String(1..128);
28+
Client : Trigger.FFI.Discord.Discord_Client_Ptr := null;
2729
end record;
2830

2931
-- Override operations from Platform_Interface

‎src/trigger/platforms/telegram/telegram-platform.adb‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
with Platform_Types;
1515
with Platform_Interface;
16+
with Trigger.FFI.Telegram;
1617

1718
package body Telegram_Platform is
1819

@@ -27,6 +28,7 @@ package body Telegram_Platform is
2728
Result.Current_Session := null;
2829
Result.Is_Connected := False;
2930
Result.Is_Authorized := False;
31+
Result.Client := Trigger.FFI.Telegram.Create_Client (Api_Id, Api_Hash, Session_Dir);
3032
end return;
3133
end Init;
3234

@@ -96,18 +98,26 @@ package body Telegram_Platform is
9698
function Connect (This : Platform_Implementation; Session : Session_Type)
9799
return Boolean is
98100
begin
99-
-- Connect to Telegram servers
100-
-- In a real implementation, this would call the Zig FFI
101-
This.Set_Connected (True);
102-
This.Set_Authorized (True);
103-
return True;
101+
-- Connect to Telegram servers via FFI
102+
if This.Client /= null then
103+
declare
104+
Result : Integer := Trigger.FFI.Telegram.Connect (This.Client);
105+
begin
106+
This.Set_Connected (Result = 1);
107+
This.Set_Authorized (Result = 1);
108+
return Result = 1;
109+
end;
110+
end if;
111+
return False;
104112
end Connect;
105113

106114
overriding
107115
procedure Disconnect (This : Platform_Implementation; Session : in out Session_Type) is
108116
begin
109-
-- Disconnect from Telegram servers
110-
-- In a real implementation, this would call the Zig FFI
117+
-- Disconnect from Telegram servers via FFI
118+
if This.Client /= null then
119+
Trigger.FFI.Telegram.Disconnect (This.Client);
120+
end if;
111121
This.Set_Connected (False);
112122
This.Set_Authorized (False);
113123
end Disconnect;
@@ -116,8 +126,10 @@ package body Telegram_Platform is
116126
function Is_Authorized (This : Platform_Implementation; Session : Session_Type)
117127
return Boolean is
118128
begin
119-
-- Check if session is authorized
120-
-- In a real implementation, this would call the Zig FFI
129+
-- Check if session is authorized via FFI
130+
if This.Client /= null then
131+
return Trigger.FFI.Telegram.Is_Authorized (This.Client) = 1;
132+
end if;
121133
return This.Is_Authorized;
122134
end Is_Authorized;
123135

@@ -252,7 +264,10 @@ package body Telegram_Platform is
252264
overriding
253265
function Ping (This : Platform_Implementation) return Boolean is
254266
begin
255-
-- Check if connected
267+
-- Check if connected via FFI
268+
if This.Client /= null then
269+
return Trigger.FFI.Telegram.Ping (This.Client) = 1;
270+
end if;
256271
return This.Is_Connected;
257272
end Ping;
258273

‎src/trigger/platforms/telegram/telegram-platform.ads‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
with Platform_Types;
1515
with Platform_Interface;
16+
with Trigger.FFI.Telegram;
1617

1718
package Telegram_Platform is
1819

@@ -26,6 +27,7 @@ package Telegram_Platform is
2627
Current_Session : access Session_Type := null;
2728
Is_Connected : Boolean := False;
2829
Is_Authorized : Boolean := False;
30+
Client : Trigger.FFI.Telegram.Telegram_Client_Ptr := null;
2931
end record;
3032

3133
-- Initialize the platform with API credentials

0 commit comments

Comments
 (0)