Laravel AT Protocol Client (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpClient\Client\Requests\Chat;
4
5use SocialDept\AtpClient\Attributes\ScopedEndpoint;
6use SocialDept\AtpClient\Client\Requests\Request;
7use SocialDept\AtpClient\Data\Responses\Chat\Convo\GetLogResponse;
8use SocialDept\AtpClient\Data\Responses\Chat\Convo\GetMessagesResponse;
9use SocialDept\AtpClient\Data\Responses\Chat\Convo\LeaveConvoResponse;
10use SocialDept\AtpClient\Data\Responses\Chat\Convo\ListConvosResponse;
11use SocialDept\AtpClient\Data\Responses\Chat\Convo\SendMessageBatchResponse;
12use SocialDept\AtpClient\Enums\Nsid\ChatConvo;
13use SocialDept\AtpClient\Enums\Scope;
14use SocialDept\AtpSchema\Generated\Chat\Bsky\Convo\Defs\ConvoView;
15use SocialDept\AtpSchema\Generated\Chat\Bsky\Convo\Defs\DeletedMessageView;
16use SocialDept\AtpSchema\Generated\Chat\Bsky\Convo\Defs\MessageView;
17
18class ConvoRequestClient extends Request
19{
20 /**
21 * Get conversation
22 *
23 * @requires transition:chat.bsky (rpc:chat.bsky.convo.getConvo)
24 *
25 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-convo
26 */
27 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getConvo')]
28 public function getConvo(string $convoId): ConvoView
29 {
30 $response = $this->atp->client->get(
31 endpoint: ChatConvo::GetConvo,
32 params: compact('convoId')
33 );
34
35 return ConvoView::fromArray($response->json()['convo']);
36 }
37
38 /**
39 * Get conversation for members
40 *
41 * @requires transition:chat.bsky (rpc:chat.bsky.convo.getConvoForMembers)
42 *
43 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-convo-for-members
44 */
45 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getConvoForMembers')]
46 public function getConvoForMembers(array $members): ConvoView
47 {
48 $response = $this->atp->client->get(
49 endpoint: ChatConvo::GetConvoForMembers,
50 params: compact('members')
51 );
52
53 return ConvoView::fromArray($response->json()['convo']);
54 }
55
56 /**
57 * List conversations
58 *
59 * @requires transition:chat.bsky (rpc:chat.bsky.convo.listConvos)
60 *
61 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-list-convos
62 */
63 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.listConvos')]
64 public function listConvos(int $limit = 50, ?string $cursor = null): ListConvosResponse
65 {
66 $response = $this->atp->client->get(
67 endpoint: ChatConvo::ListConvos,
68 params: compact('limit', 'cursor')
69 );
70
71 return ListConvosResponse::fromArray($response->json());
72 }
73
74 /**
75 * Get messages
76 *
77 * @requires transition:chat.bsky (rpc:chat.bsky.convo.getMessages)
78 *
79 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-messages
80 */
81 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getMessages')]
82 public function getMessages(
83 string $convoId,
84 int $limit = 50,
85 ?string $cursor = null
86 ): GetMessagesResponse {
87 $response = $this->atp->client->get(
88 endpoint: ChatConvo::GetMessages,
89 params: compact('convoId', 'limit', 'cursor')
90 );
91
92 return GetMessagesResponse::fromArray($response->json());
93 }
94
95 /**
96 * Send message
97 *
98 * @requires transition:chat.bsky (rpc:chat.bsky.convo.sendMessage)
99 *
100 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-send-message
101 */
102 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.sendMessage')]
103 public function sendMessage(string $convoId, array $message): MessageView
104 {
105 $response = $this->atp->client->post(
106 endpoint: ChatConvo::SendMessage,
107 body: compact('convoId', 'message')
108 );
109
110 return MessageView::fromArray($response->json());
111 }
112
113 /**
114 * Send message batch
115 *
116 * @requires transition:chat.bsky (rpc:chat.bsky.convo.sendMessageBatch)
117 *
118 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-send-message-batch
119 */
120 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.sendMessageBatch')]
121 public function sendMessageBatch(array $items): SendMessageBatchResponse
122 {
123 $response = $this->atp->client->post(
124 endpoint: ChatConvo::SendMessageBatch,
125 body: compact('items')
126 );
127
128 return SendMessageBatchResponse::fromArray($response->json());
129 }
130
131 /**
132 * Delete message for self
133 *
134 * @requires transition:chat.bsky (rpc:chat.bsky.convo.deleteMessageForSelf)
135 *
136 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-delete-message-for-self
137 */
138 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.deleteMessageForSelf')]
139 public function deleteMessageForSelf(string $convoId, string $messageId): DeletedMessageView
140 {
141 $response = $this->atp->client->post(
142 endpoint: ChatConvo::DeleteMessageForSelf,
143 body: compact('convoId', 'messageId')
144 );
145
146 return DeletedMessageView::fromArray($response->json());
147 }
148
149 /**
150 * Update read status
151 *
152 * @requires transition:chat.bsky (rpc:chat.bsky.convo.updateRead)
153 *
154 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-update-read
155 */
156 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.updateRead')]
157 public function updateRead(string $convoId, ?string $messageId = null): ConvoView
158 {
159 $response = $this->atp->client->post(
160 endpoint: ChatConvo::UpdateRead,
161 body: compact('convoId', 'messageId')
162 );
163
164 return ConvoView::fromArray($response->json()['convo']);
165 }
166
167 /**
168 * Mute conversation
169 *
170 * @requires transition:chat.bsky (rpc:chat.bsky.convo.muteConvo)
171 *
172 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-mute-convo
173 */
174 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.muteConvo')]
175 public function muteConvo(string $convoId): ConvoView
176 {
177 $response = $this->atp->client->post(
178 endpoint: ChatConvo::MuteConvo,
179 body: compact('convoId')
180 );
181
182 return ConvoView::fromArray($response->json()['convo']);
183 }
184
185 /**
186 * Unmute conversation
187 *
188 * @requires transition:chat.bsky (rpc:chat.bsky.convo.unmuteConvo)
189 *
190 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-unmute-convo
191 */
192 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.unmuteConvo')]
193 public function unmuteConvo(string $convoId): ConvoView
194 {
195 $response = $this->atp->client->post(
196 endpoint: ChatConvo::UnmuteConvo,
197 body: compact('convoId')
198 );
199
200 return ConvoView::fromArray($response->json()['convo']);
201 }
202
203 /**
204 * Leave conversation
205 *
206 * @requires transition:chat.bsky (rpc:chat.bsky.convo.leaveConvo)
207 *
208 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-leave-convo
209 */
210 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.leaveConvo')]
211 public function leaveConvo(string $convoId): LeaveConvoResponse
212 {
213 $response = $this->atp->client->post(
214 endpoint: ChatConvo::LeaveConvo,
215 body: compact('convoId')
216 );
217
218 return LeaveConvoResponse::fromArray($response->json());
219 }
220
221 /**
222 * Get log
223 *
224 * @requires transition:chat.bsky (rpc:chat.bsky.convo.getLog)
225 *
226 * @see https://docs.bsky.app/docs/api/chat-bsky-convo-get-log
227 */
228 #[ScopedEndpoint(Scope::TransitionChat, granular: 'rpc:chat.bsky.convo.getLog')]
229 public function getLog(?string $cursor = null): GetLogResponse
230 {
231 $response = $this->atp->client->get(
232 endpoint: ChatConvo::GetLog,
233 params: compact('cursor')
234 );
235
236 return GetLogResponse::fromArray($response->json());
237 }
238}