Wallu - Developer API
Wallubot provides an easy-to-use API for developers to integrate Wallu into other platforms and projects.
Creating an Addon
- Go to the addons page and create a new API key
- Use the API key in your addon to send messages to Wallu
- The API is designed to be simple and easy to use
- Easy to add Wallu to any other platform and will work just like the Discord bot
Documentation
Example: Use Wallu's AI to answer a question anywhere
Node.js
const axios = require('axios')
// or "import axios from 'axios'"
const API_URL = 'https://api.wallubot.com/v1'
async function walluExample() {
const response = await axios.post(`${API_URL}/on-message`, {
addon: {
name: 'my-addon',
version: '0.1.0',
},
channel: {
// You can generate one, for example, using the current group chat name/ID or generate a random one. The bot may use this to keep track of previous messages.
id: '123456789',
// For example, in the Wallu Telegram addon this is the group chat name
name: 'Addon Channel #1'
},
user: {
// Some kind of identifier for this user. The bot may use this to keep track of previous messages.
id: '123456789',
// The username of the user (the bot may use this to personalize the response)
username: 'John Doe',
// Whether the user is a staff member. You can also just leave this false. (This mainly just affects some settings like the "avoid answering staff members unless mentioned")
is_staff_member: false,
},
message: {
// ID of the message, or just generate a random ID for this.
id: '123456789',
// If true, the bot is forced to answer, otherwise it may not answer.
is_bot_mentioned: true,
// The message content
content: 'how do I reset my password??'
},
configuration: {
// The emoji type to use. If set to 'none', the bot will not use any emojis.
emoji_type: 'unicode',
// Whether to include the sources links in the response.
include_sources: false,
}
}, {
headers: {
// You would use your own key here (or from env var)
// It's recommended to use a different key for each addon
// Find your API key here: https://panel.wallubot.com/addons
// You should always keep this key private and not publish it.
"X-API-Key": process.env.WALLU_API_KEY,
}
})
console.log(response.data)
// {
// response: {
// message: 'Click "forgot my password" on the login page. For more information, you can visit the following link: <https://example.com>.'
// }
// }
}
walluExample().then(() => console.log("DONE!"))
Example: Sync GitHub files as a document
This example shows how you could, for example, all *.md
and *.txt
files from your GitHub repository as one Wallu document and keep it up to date. This can be more reliable than importing a website and updates immediately.
On first run, it will create a new document (with your-external-id
ID - CHANGE IT) and later it will update the same document.
Steps
- You probably already have a github repository with some markdown files.
- Go to the Wallu's addons page and create a new API key
- Go to your GitHub repository settings and add a new secret with the key
WALLUBOT_API_KEY
and the value of the API key you created in step 2. - Create a new GitHub Actions workflow file in your repository (e.g.,
.github/workflows/sync-wallu-document.yml
) with the following content. - Customize the
FILE_PATTERNS
andEXTERNAL_DOCUMENT_ID
variables in the workflow file. - Commit and push the changes to your repository.
Help with GitHub actions: GitHub Actions Documentation
Note: Wallu has a limit for the document size.
.github/workflows/sync-wallu-document.yml
name: Update Wallu's Documentation
on:
push:
branches:
- main # Change this to your main branch
jobs:
upsert-wallu-document:
runs-on: ubuntu-latest
env:
# Customize FILE_PATTERNS by listing the glob patterns of files you wish to include
# Examples:
# '**/**.md' -> Include all Markdown files ("**" = including subdirectories)
# 'config/*.{yaml,yml}' -> Include YAML (.yaml and .yml) files from "config" directory ("*" = not in subdirectories)
# '!**/wallu_output/**' -> Use "!" to exclude the temp files this script creates
FILE_PATTERNS: |
'**/**.md'
'config/*.{yaml,yml}'
'!**/wallu_output/**'
# Change the ID that is used to find the document to update instead of creating a new one each time.
# Set it to something like your repository name.
EXTERNAL_DOCUMENT_ID: "your-external-id"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Concatenate matching files with separators
run: |
mkdir -p wallu_output
> wallu_output/combined_docs.txt
temp_file_list=$(mktemp)
for pattern in $FILE_PATTERNS; do
echo "Processing pattern: $pattern"
find $pattern -type f >> "$temp_file_list" 2>/dev/null || true
done
# Deduplicate and sort the file list
sort -u "$temp_file_list" > sorted_unique_files.txt
# Process each unique file
while IFS= read -r filename; do
echo "Adding file: $filename"
echo -e "\n\n### $(basename "$filename") ###\n" >> wallu_output/combined_docs.txt
cat "$filename" >> wallu_output/combined_docs.txt
done < sorted_unique_files.txt
- name: Upload new document content
env:
# Add WALLUBOT_API_KEY to your repository secrets
# You can create it here: https://panel.wallubot.com/addons
# DO NOT ADD IT HERE DIRECTLY (OR PUBLISH IT ANYWHERE)
API_KEY: ${{ secrets.WALLUBOT_API_KEY }}
# No need to change the API_ENDPOINT
API_ENDPOINT: "https://api.wallubot.com/v1/document/upsert/${EXTERNAL_DOCUMENT_ID}"
# Now we upload the new document content to Wallu. Old content will be replaced.
# Wallu will automatically process the changes in the background and start using it.env:
run: |
CONTENT=$(jq -Rs '.' wallu_output/combined_docs.txt)
curl -X PUT "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-d "{\"content\": $CONTENT}"
Example Projects
- wallu-telegram - Enables Wallu to answer questions on Telegram group chats (just like on Discord).
- wallu-spigot - Enables Wallu to answer questions on a Minecraft server.