Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Documentation soon to be available on Hackage. For now, see [markandrus.github.i

For TwiML, see [twiml-haskell](http://github.com/markandrus/twiml-haskell).

Example
Example 1 - using environment variables
-------

You can create a REST API client and fetch the calls resources as follows
You can create a REST API client, fetch the calls, or send a message as follows:

```hs
{-#LANGUAGE OverloadedStrings #-}
Expand All @@ -38,11 +38,54 @@ main = runTwilio' (getEnv "ACCOUNT_SID")
liftIO $ print calls

-- Send a Message.
let body = PostMessage "+14158059869" "+14158059869" "Oh, hai"
let fromPhone = "+14158059869"
let toPhone = "+14158059869"
let body = PostMessage receivingPhone sendingPhone "Oh, hai"
message <- post body
liftIO $ print message
```

Example 2 - using SID and secret embedded in the code
-------

You can create a REST API client and send a message as follows:

```hs
{-#LANGUAGE OverloadedStrings #-}

module Main where

import Control.Monad.IO.Class (liftIO)
import Data.Text (Text)
import Twilio
import Twilio.Messages
import Twilio.Types.SID

parseCredentials :: Text -> Text -> Maybe Credentials
parseCredentials accountSID authToken =
case parseAuthToken authToken of
Just authToken ->
(case parseSID accountSID of
Just accountSID ->
Just (accountSID, authToken)
Nothing -> Nothing)
Nothing -> Nothing

main :: IO ()
main =
let accountSID = "youraccountSID"
authToken = "yourauthToken"
in case parseCredentials accountSID authToken of
Just credentialsPassed ->
runTwilio ( credentialsPassed ) $ do
let fromPhone = "+14158059869"
let toPhone = "+14158059869"
let body = PostMessage receivingPhone sendingPhone "Oh, hai"
message <- post body
liftIO $ print message
Nothing -> print "Something bad happened, you have poorly formed credentials."
```

Contributing
------------

Expand Down