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

Safe HaskellNone
LanguageHaskell98

Network.AMI

Contents

Synopsis

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 AMI a = ReaderT (TVar AMIState) IO a Source

The AMI monad

data Action Source

Action packet (sent to Asterisk)

Instances

data Response Source

Response packet (received from Asterisk)

Instances

data Event Source

Event packet (received from Asterisk)

Constructors

Event EventType Parameters 

Instances

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

Functions

withAMI :: ConnectInfo -> AMI a -> IO a Source

Connect, execute acions, disconnect

withAMI_MD5 :: ConnectInfo -> AMI a -> IO a Source

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