Use atproto actions with ease in iOS shortcuts
1//
2// shortcut
3//
4// Created by Bailey Townsend on 6/29/25.
5//
6
7import ATProtoKit
8import AppIntents
9import Foundation
10
11struct RecordAppEntity: TransientAppEntity, Codable {
12
13 /// The URI for the record.
14 @Property(title: "Record's URI")
15 public var uri: String
16
17 /// The CID hash for the record.
18 @Property(title: "Record's CID")
19 public var cid: String
20
21 /// Can change output from the variable to dictionary in shortcuts
22 @Property(title: "Value")
23 var value: IntentFile?
24
25 var id: String { uri }
26
27 static var typeDisplayName: LocalizedStringResource = "Record"
28
29 static var typeDescription: LocalizedStringResource? =
30 "Response from a PDS when you get a record"
31
32 var displayRepresentation: AppIntents.DisplayRepresentation {
33 var anonymousObject: [String: CodableValue] = [
34 "uri": CodableValue(stringLiteral: self.uri),
35 "cid": CodableValue(stringLiteral: self.cid),
36 ]
37
38 do {
39 if let valueData = self.value?.data {
40 let decoder = JSONDecoder()
41
42 anonymousObject["value"] = try decoder.decode(
43 CodableValue.self, from: valueData)
44 }
45 guard let fullJsonData = try anonymousObject.toJsonData() else {
46 throw GenericIntentError.general
47 }
48 let jsonString =
49 String(data: fullJsonData, encoding: .utf8) ?? ""
50
51 return DisplayRepresentation(title: "\(jsonString)")
52 } catch {
53 return DisplayRepresentation(
54 title: "uri: \(uri)\n recordCID:\(cid)")
55 }
56 }
57
58 static var typeDisplayRepresentation: TypeDisplayRepresentation {
59 TypeDisplayRepresentation(
60 name: LocalizedStringResource("ATProtocol Record", table: "AppIntents")
61
62 )
63 }
64
65}