NoxiousPluK
Send messages using the Telegram Bot API

Supported Games
GameServerKingsGameServerKings

This allows other plugins to send messages using the Telegram Bot API.

Getting Started

Getting your Bot API Token

  1. Talk to BotFather on Telegram and create a bot
  2. Optional: Add the bot to the chat group you want the messages in (alternatively you can have it talk directly to you)
  3. Get your Bot API Token
  4. Add RawDataBot or another helper to the chat group you want the messages in, or talk to that bot directly (Look for message->chat->id in the JSON output)
  5. Edit Telegram.json in the config-directory
  6. Set the API key and chat ID's accordingly
  7. Use oxide.reload Telegram in the server console or RCON to reload the plugin

Configuration

{
  "Telegram Bot API Key": "[bot id here]:[access token here]",
  "Default ID for messages": -12345,
  "ID for error messages": -12345,
  "Try sending error messages to Telegram": true,
  "Announce plugin (re)load to Telegram": false
}

For Developers

API Methods

public void SendTelegramMessage(string message, long chatID = 0, bool escape = false, string parseMode = "Markdown")

Send a message. Variables are:

  • message: The message contents
  • chatID: The target ID, if 0 it will use the specified default from the config
  • escape: If set to true, the entire message will be escaped
  • parseMode: The message parse mode, defaults to markdown but you can also use markdown V2 or HTML; see Telegram API Documentation for more information
public string Escape(string Input)

Escape strings to make them Telegram-API friendly; you might want to do this with things like player names, but if you're not using markdown in messages you can also escape the entire message just to be safe.

Here is an example of your server sending status notifications:

using Oxide.Core.Plugins;

namespace Oxide.Plugins
{
    [Info("Telegram Status Notifier", "NoxiousPluK", "0.1.0")]
    [Description("Ping admins on server restart")]
    class TelegramStatusNotifier : CovalencePlugin
    {
        [PluginReference]
        private Plugin TelegramBotAPI;

        void OnServerInitialized(bool initial)
        {
            if (initial)
            {
                TelegramBotAPI?.Call("SendTelegramMessage", $"ℹ *{ConVar.Server.hostname}*\r\nšŸ”ŗ *Server is starting up.*");
            }
        }

        void OnServerShutdown()
        {
            TelegramBotAPI?.Call("SendTelegramMessage", $"ℹ *{ConVar.Server.hostname}*\r\nšŸ”» *Server is shutting down.*");
        }
    }
}

Which looks like this in Telegram:

Example of server notification message

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.