Bot.sendVideo()方法在Node.js Telegram Bot API中使用。該Node.js模塊可與官方Telegram Bot API進行交互。此方法用於發送格式不同的視頻。
用法:
TelegramBot.sendVideo(chatId, location)
參數:該方法接受上述和以下描述的兩個參數:
- chatId:chatId是聊天的唯一標識符,可以是私有,組,超級組或通道,而userId是僅用於用戶或漫遊器的唯一標識符。每個客戶的消息均包含chatId。
- Location:我們要以String格式發送的視頻的位置。
返回類型:該函數的返回類型為void。
安裝模塊:使用以下命令安裝模塊:
npm i telegram-bot-api
獲取 key 的步驟:
- 首先,以電報形式從BOTFATHER獲取GET BOT_TOKEN。隻需在Telegram中搜索BOTFATHER,然後選擇經過驗證的BOTFATHER,如下所示:
- 鍵入/start,然後單擊/newbot,如下所示:
- 現在,鍵入機器人的名稱,並且該名稱必須唯一。
- 現在,隻需從BotFather複製令牌。對於刪除令牌,隻需在BotFather中搜索/delete令牌即可。
項目結構:
檔案名稱:bot.js
var token = 'Enter the token';
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot(token, {polling:true});
// Matches "/echo [whatever]"
bot.onText(/\/echo(.+)/, (msg, match) => {
// The 'msg' is the received Message from Telegram
// and 'match' is the result of executing the regexp
// above on the text content of the message
const chatId = msg.chat.id;
// The captured "whatever"
const resp = match[1];
// Reply the message
bot.sendMessage(chatId, "Your Video is");
// Sending the video to the Telegram Bot
bot.sendVideo(chatId, "h.mp3");
});
使用以下命令運行bot.js文件:
node bot.js
輸出:
相關用法
- Node.js console.timeLog()用法及代碼示例
- Node.js GM charcoal()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
注:本文由純淨天空篩選整理自zack_aayush大神的英文原創作品 Node.js Bot.sendVideo() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。