Erlang tone checker quickstart
Send text to the tone endpoint. The response ranks overall tones and returns a separate probability breakdown for every sentence.
No language-specific SDK is required. The example uses a standard or commonly used HTTP client to call Sapling's JSON API.
Erlang
/api/v1/tone
This example uses OTP's httpc client and the jsx JSON library.
inets:start(),
ssl:start(),
ApiKey = os:getenv("SAPLING_API_KEY"),
true = ApiKey =/= false,
Url = "https://api.sapling.ai/api/v1/tone",
Headers = [
{"Authorization", "Bearer " ++ ApiKey},
{"Accept", "application/json"}
],
Body = jsx:encode(#{
<<"text">> => <<"Really stoked about this! Will it be ready by next week?">>
}),
{ok, {{_Version, Status, _Reason}, _ResponseHeaders, ResponseBody}} =
httpc:request(post, {Url, Headers, "application/json", Body}, [], []),
true = Status >= 200 andalso Status < 300,
io:format("~s~n", [ResponseBody]).
Example response
application/json
{
"overall": [
[0.9247, "curious", "🤓"],
[0.0455, "excited", "😀"],
[0.0057, "confused", "😕"]
],
"results": [
[[0.9937, "excited", "😀"]],
[[0.5469, "confused", "😕"], [0.3993, "curious", "🤓"]]
],
"sents": [
"Really stoked about this!",
"Will it be ready by next week?"
]
}
Probabilities are returned in descending order as probability, tone, and emoji tuples. Use sentence results when a message contains mixed tones.
About Erlang
Erlang is a programming language for the Erlang virtual machine. It is designed for distributed, fault-tolerant, and highly concurrent/parallelizable systems. Applications of Erlang include WhatsApp and telephony switches.