@@ -47,37 +47,42 @@ where
47
47
-- > Prelude Netowrk.Matrix.Client> :set prompt "> "
48
48
-- > > :set -XOverloadedStrings
49
49
-- > > :type getTokenOwner
50
- -- > getTokenOwner :: ClientSession -> MatrixIO WhoAmI
50
+ -- > getTokenOwner :: MatrixIO UserID
51
51
52
52
-- $session
53
- -- Most functions require 'Network.Matrix.Client.ClientSession' which carries the
54
- -- endpoint url and the http client manager.
55
- --
56
- -- The only way to get the client is through the 'Network.Matrix.Client.createSession' function:
53
+ -- Most functions operates in the 'MatrixIO' context, and to get their output you need to use
54
+ -- the 'runMatrixIO' helper. This helper expects a 'ClientSession' that can be created with
55
+ -- 'Network.Matrix.Client.createSession':
57
56
--
58
57
-- > > token <- getTokenFromEnv "MATRIX_TOKEN"
59
- -- > > sess <- createSession "https://matrix.org" token
60
- -- > > getTokenOwner sess
61
- -- > Right (WhoAmI "@tristanc_:matrix.org")
58
+ -- > > session <- createSession "https://matrix.org" token
59
+ -- > > runMatrixIO session getTokenOwner
60
+ -- > Right (UserID "@tristanc_:matrix.org")
61
+ --
62
+ -- For the purpose of this tutorial, we can create a `withSession` wrapper:
63
+ --
64
+ -- > > let withSession = runMatrixIO session :: MatrixIO a -> IO (Either MatrixError a)
65
+ -- > > withSession getTokenOwner
66
+ -- > Right (UserID "@tristanc_:matrix.org")
62
67
63
68
-- $sync
64
69
-- Create a filter to limit the sync result using the 'Network.Matrix.Client.createFilter' function.
65
70
-- To keep room message only, use the 'Network.Matrix.Client.messageFilter' default filter:
66
71
--
67
- -- > > Right userId <- getTokenOwner sess
68
- -- > > Right filterId <- createFilter sess userId messageFilter
69
- -- > > getFilter sess (UserID "@gerritbot:matrix.org") filterId
72
+ -- > > Right userId <- withSession getTokenOwner
73
+ -- > > Right filterId <- withSession ( createFilter userId messageFilter)
74
+ -- > > withSession (getFilter userId filterId)
70
75
-- > Right (Filter {filterEventFields = ...})
71
76
--
72
77
-- Call the 'Network.Matrix.Client.sync' function to synchronize your client state:
73
78
--
74
- -- > > Right syncResult <- sync sess (Just filterId) Nothing (Just Online) Nothing
79
+ -- > > Right syncResult <- withSession ( sync (Just filterId) Nothing (Just Online) Nothing)
75
80
-- > > putStrLn $ take 512 $ show (getTimelines syncResult)
76
81
-- > SyncResult {srNextBatch = ...}
77
82
--
78
83
-- Get next batch with a 300 second timeout using the @since@ argument:
79
84
--
80
- -- > > Right syncResult' <- sync sess (Just filterId) (Just (srNextBatch syncResult)) (Just Online) (Just 300000)
85
+ -- > > Right syncResult' <- withSession ( sync (Just filterId) (Just (srNextBatch syncResult)) (Just Online) (Just 300000) )
81
86
--
82
87
-- Here are some helpers function to format the messages from sync results, copy them in your REPL:
83
88
--
96
101
-- Use the 'Network.Matrix.Client.syncPoll' utility function to continuously get events,
97
102
-- here is an example to print new messages, similar to a @tail -f@ process:
98
103
--
99
- -- > > syncPoll sess (Just filterId) (Just (srNextBatch syncResult)) (Just Online) printTimelines
104
+ -- > > withSession ( syncPoll (Just filterId) (Just (srNextBatch syncResult)) (Just Online) printTimelines)
100
105
-- > room1| test-user: Hello world!
101
106
-- > ...
102
107
@@ -112,5 +117,5 @@ where
112
117
-- > > tokenId <- getTokenFromEnv "MATRIX_IDENTITY_TOKEN"
113
118
-- > > sessId <- createIdentitySession "https://matrix.org" tokenId
114
119
-- > > Right hd <- hashDetails sessId
115
- -- > > identityLookup sessId hd (Email "[email protected] ")
120
+ -- > > runMatrixIO sessionId (identityLookup hd (Email "[email protected] ") )
116
121
-- > Right (Just (UserID "@tristanc_:matrix.org"))
0 commit comments