AMI-0.1: Low-level bindings for Asterisk Manager Interface (AMI).

Safe Haskell | None

Network.AMI

Contents

- Usage
- Types
- Functions

Synopsis

- 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 = ByteString Source

type EventType = ByteString Source

type ActionID = Integer Source

type ResponseType = ByteString Source

type EventHandler = Parameters -> IO ()Source

type AMI a = ReaderT (TVar AMIState) IO aSource

The AMI monad

data Action Source

Action packet (sent to Asterisk)

Constructors

Action ActionID ActionType Parameters |

Instances

Eq Action |
Show Action |

data Response Source

Response packet (received from Asterisk)

Constructors

Response ActionID ResponseType Parameters [ByteString] |

Instances

Eq Response |
Show Response |

data Event Source

Event packet (received from Asterisk)

Constructors

Event EventType Parameters |

Instances

Eq Event |
Show Event |

data ConnectInfo Source

Info needed to connect and authenticate in Asterisk

Constructors

ConnectInfo |

Fields

ciHost :: String

  Host with Asterisk server (e.g. `localhost`)

ciPort :: Int

  Port of Asterisk server (usually 5038)

ciUsername :: ByteString

  Username

ciSecret :: ByteString

  Secret

Instances

Eq ConnectInfo |
Show 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 Response Source

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