API Access
Conversation mode (New)
To see an example of conversation mode, please refer to this gist on Github.
Query your bot
Mottle provides a simple JSON API for talking to your bot.
You will find everything you need on the Publish / API Page in your account.
Sample code below:
- JavaScript
- Python
- Curl
const request = require("request")
const BOT_ID = "YOUR_BOT_ID"
const BOT_SECRET = "YOUR_BOT_SECRET"
const question = "What is your name?"
const url = `https://api.mottle.com/connect?bot=${BOT_ID}`
const headers = { "Content-Type": "application/json" }
const data = { secret: BOT_SECRET, question: question }
request.post({ url, headers, json: data }, (err, response, body) => {
if (err) {
console.error(err)
} else {
if (body.error) {
console.log(body.error)
} else {
console.log(body.answer)
}
}
})
import requests
BOT_ID = "YOUR_BOT_ID"
BOT_SECRET = "YOUR_BOT_SECRET"
question = "What is your name?"
url = f"https://api.mottle.com/connect?bot={BOT_ID}"
headers = {"Content-Type": "application/json"}
data = {"secret": BOT_SECRET, "question": question}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
response_json = response.json()
if "error" in response_json:
print(response_json["error"])
else:
print(response_json["answer"])
else:
print("Request failed.")
curl -X POST "https://api.mottle.com/connect?bot={YOUR_BOT_ID}" \
-H 'Content-Type: application/json' \
-d '{"secret": "{YOUR_BOT_SECRET}", "question": "What is your name?"}'
Email mode
To enable email mode, append &mode=email
to the "Connect" API URL. For example:
https://api.mottle.com/connect?bot=1234-abcd&mode=email