- type Parameters = [(ByteString, ByteString)]
- type ActionType = ByteString
- type EventType = ByteString
- type ActionID = Integer
- type ResponseType = ByteString
- type EventHandler = Parameters -> IO ()
- type AMI a = ReaderT (TVar AMIState) IO a
- data Action = Action ActionID ActionType Parameters
- data Response = Response ActionID ResponseType Parameters [ByteString]
- data Event = Event EventType Parameters
- data ConnectInfo = ConnectInfo {
- ciHost :: String
- ciPort :: Int
- ciUsername :: ByteString
- ciSecret :: ByteString
- withAMI :: ConnectInfo -> AMI a -> IO a
- withAMI_MD5 :: ConnectInfo -> AMI a -> IO a
- query :: ActionType -> Parameters -> AMI Response
- handleEvent :: EventType -> EventHandler -> AMI ()
Usage
import Network.AMI info :: ConnectInfo info = ConnectInfo { ciHost = "localhost" , ciPort = 5038 , ciUsername = "admin" , ciSecret = "PASSWORD" } main :: IO () main = withAMI_MD5 info $ do handleEvent "FullyBooted" onBooted mail <- query "MailboxCount" [("Mailbox","900")] liftIO $ print mail jabber <- query "JabberSend" [("Jabber", "asterisk"), ("JID", "someone@example.com"), ("ScreenName", "asterisk"), ("Message", "Jabber via AMI")] liftIO $ print jabber onBooted :: EventHandler onBooted ps = liftIO $ do putStrLn "Asterisk is fully booted." print ps
Types
type Parameters = [(ByteString, ByteString)]Source
Action or response or event parameters
type ActionType = ByteStringSource
type EventType = ByteStringSource
type ResponseType = ByteStringSource
type EventHandler = Parameters -> IO ()Source
Action packet (sent to Asterisk)
Response packet (received from Asterisk)
Event packet (received from Asterisk)
data ConnectInfo Source
Info needed to connect and authenticate in Asterisk
ConnectInfo | |
|
Functions
withAMI :: ConnectInfo -> AMI a -> IO aSource
Connect, execute acions, disconnect
withAMI_MD5 :: ConnectInfo -> AMI a -> IO aSource
Connect (using MD5 challenge), execute acions, disconnect
query :: ActionType -> Parameters -> AMI ResponseSource
Send an Action packet and return the response.
CAUTION: the response value should be evaluated in order to be removed from internal responses queue. Leaving response value un-evaluated (e.g. unused) will cause memory leak.
handleEvent :: EventType -> EventHandler -> AMI ()Source
Add an event handler