The Bahá'í Bot has default support for the chat server, Discord, but it could be applied for other applications, including even client-side browser-based apps.
npm i bahaibotYou can add the "9star" and "Bstar" emojis to your server to have them used by the Bot. (If you can contribute open source versions of the "awesome" emoji or our Persian new year "sabzi", we'd welcome a PR!.)
Otherwise, they will be silently ignored.
You can add this command to one of your scripts in package.json:
bahaibot
--checkins- Boolean on whether to perform automated checkins--locales- (Currentlyen-USonly, the default)
For Discord usage:
import 'bahaibot';or:
import buildBahaiBot from 'bahaibot/discordBot';
const bahaibot = buildBahaiBot({
// ... Override default arguments
});For non-Discord usage:
import buildBahaiBot from 'bahaibot/bot';
const bahaibot = buildBahaiBot({
// ... Supply browser values
});Note that for non-Discord usage, you must supply your own implementations to the API (see the API below).
For the rarer use case that one wishes an integrated client-server environment
which runs in a browser context like an add-on or a web app where there is only
one (trusted) user, you can use the integratedClientServerBot which has
fs and getPath implementations baked in:
// If you do not want a build step, you can use this import instead:
// import buildBahaiBot from
// './node_modules/bahaibot/dist/integratedClientServerBot.js';
import buildBahaiBot from 'bahaibot/dist/integratedClientServerBot.js';
const bahaibot = buildBahaiBot({
// Supply implementations for:
dialogflow,
Discord
});Note that this "browser" usage is not for a typical client-server architecture, but rather for more of a self-contained browser add-on or web app which used HTML/JavaScript technologies but was not necessarily interactive or managing privileges between different users on a server. The HTTP middleware which could facilitate such a bot might be added in the future.
buildBahaiBot({
// Boolean whether to run checkin code
checkins,
// Defaults to `['en-US']` in Node and otherwise, defaults to checking
// `navigator.languages` for any matches with the app's locales, adding
// `en-US` if none are found.
locales,
// THESE ARE REQUIRED FOR NON-NODE IMPLEMENTATIONS (Node will auto-supply
// all of the following)
fetch, // Defaults to `globalThis.fetch` for non-Node; Node auto-supplies
// These can either be imported as global values or supplied via a direct
// ESM `/node_modules` import (or build step).
i18n, // Defaults to `globalThis.intlDom.i18n`, assuming UMD of
// `intl-dom` dep. used
striptags, // Defaults to `globalThis.striptags`, assuming UMD of `striptags`
// exists
Discord, // A Discord implementation
client, // A Discord.Client implementation (defaults to `new Discord.Client`)
dialogflow, // dialogflow implementation
fs, // The Node `fs/promises`
// Provided `system` value of `getPath('settings.json')` JSON; returns
// settings object `system.development` by default, though in Node,
// allowing for a `--production` flag to trigger getting `system.production`
// instead.
getSettings,
getPath // The Node equivalent of:
// `require('path').join(process.cwd(), path)`
// May be passed `settings.json` or `PROJECT_JSON` within
// `settings.json`
});token- Get this string from your Bot page on the Discord Developer Dashboard; be sure not to publish itdisableNotMentioned- Defaults tofalsewelcomeChannel- Defaults to 'welcome'awesomeEmoji- Defaults to 'awesome'helpTeam- Defaults toDiscordConstants.BAHAI_FYI_HELP_TEAMrulesChannel- Defaults toDiscordConstants.BAHAI_FYI_RULES_CHANNEL_IDPUPPET_AUTHOR- Defaults toDiscordConstants.USER_ABADMIN_PERMISSION- Defaults toDiscordConstants.ADMIN_PERMISSIONADMIN_IDS- Defaults toDiscordConstants.ADMIN_IDSADMIN_ROLES- Defaults toDiscordConstants.ADMIN_ROLESdisabledCommandGroups- Defaults to[]enabledCommandGroups- Defaults to['*']embedColor- The color borderembedTextLimit- The maximum text limitPROJECT_ID- dialogflow service account key (see https://cloud.google.com/dialogflow/es/docs/quick/setup#sa-create)PROJECT_JSON- dialogflow service account key json file (see https://cloud.google.com/dialogflow/es/docs/quick/setup#sa-create)bstarEmoji- Defaults to 'bstar'checkinGuilds= Defaults to:
checkinGuilds = [
{
guildID: DiscordConstants.BAHAI_LAB_GUILD_ID,
guildName: getLocalizedSetting('labServerName'),
guildChannels: [
{
id: DiscordConstants.BAHAI_LAB_BOT_TESTING_CHANNEL_ID,
greetings: getLocalizedSetting('debugCheckin', {
defaultValue: greets.debugCheckin
}),
reportUptime: true
}
]
},
{
guildID: DiscordConstants.BAHAI_FYI_GUILD_ID,
guildName: getLocalizedSetting('serverName'),
guildChannels: [
{
id: DiscordConstants.BAHAI_FYI_GENERAL_CHANNEL_ID,
greetings: getLocalizedSetting('fyiCheckin-general', {
defaultValue: greets.fyiCheckin.general
})
},
{
id: DiscordConstants.BAHAI_FYI_STUDY_HALL_CHANNEL_ID,
bpToday: true
}
]
},
{
guildID: DiscordConstants.BAHAI_WIKIS_GUILD_ID,
guildName: "Bahá'í Wikis",
guildChannels: [
{
id: DiscordConstants.BAHAI_WIKIS_GENERAL_CHANNEL_ID,
greetings: getLocalizedSetting('bahaiWikisCheckin-general', {
defaultValue: greets.fyiCheckin.general
})
}
]
}
];Hidden Words
See CONTRIBUTING.md.
-
Waiting: Update to discord.js v15.0.0 when comes out
-
Go through in-code to-dos
- complete i18nizing messages
-
See about establishing maintenance of bot on own server
-
See about any refactoring needed to allow to work with bahai-matrix-bot and easier for website; make website version support opening URLs on behalf of user for full context of the Writings and support speech synthesis
-
Augment Dialogflow fallbacks with Bahaipedia search: A new intent called "General knowledge" has been created in Dialogflow. When the bot gets results back from Dialogflow, it should check to see if this intent has been matched: (i.e.
["queryResult"]["intent"]["displayName"] == "General knowledge"). If it has, it should follow up its own response with a Bahaipedia search for the given phrase. Ex.: A user message reading "Who was Robert Turner" would trigger the general knowledge intent and follow up with the same results as/bp Robert Turner.