How to play sound with a music discord bot on heroku - heroku

I'm creating a Discord Music Bot in discord.js, I already installed ffmpeg, and everything seems to work normally, but when I execute play command, bot joins a channel, send a message, but doesn't play anything, I've already checked console and it doesn't log anything.
I know it's not a problem with code since it works perfectly locally, the problem is when I try to use heroku, I thought it could be a opusscript problem but I don't know.

I don't find code relevant here, since it works perfectly in my localhost, but when I start to host it at Heroku, nothing happens.
Here you have it, maybe there's an error, but as I said I think the problem is with opusscript or node-opus.
Here are my Heroku buildpacks
And this is my code:
const ytdl = require('ytdl-core');
let voiceChn = message.member.voiceChannel;
if(!voiceChn) return message.channel.send('¡Join a voice channel first!.');
if(!args) return message.channel.send('Add a youtube URL to play it.');
voiceChn.join()
.then(connection => {
const url = ytdl(args.join(' '), { filter : 'audioonly' });
const dispatcher = connection.playStream(url);
message.delete();
message.channel.send('Now playing : '+ args);
}).catch(console.error);

For what its worth I am seeing a very similar issue. My bot should join the channel, play a sound clip from a S3 bucket (which is made public), and then leave.
Here's my code:
async function executePlaySoundCommand(message, filePath) {
try {
const voiceChannel = message.member.voiceChannel;
const connection = await voiceChannel.join();
console.log(`filePath: ${filePath}`);
const file = `${process.env.S3_URL}/${filePath}`;
console.log(`file: ${file}`);
const dispatcher = await connection.playArbitraryInput(file);
console.log('Playback finished');
dispatcher.on('end', () => {
voiceChannel.leave();
});
} catch (err) {
console.log(err);
}
}
Locally the bot will join the channel, play the sound and then leave as expected. However in heroku, the bot will join the channel, then immediately leave.
Below are the sanitized logs from heroku:
Executing <command-name> command
filePath: <audio-file>.mp3
file: https://s3-eu-west-1.amazonaws.com/<s3-bucket-name>/<audio-file>.mp3
Playback finished
I don't think there's anything wrong with my code(?), looking into ffmpeg protocols to see if I have missed something.

Related

how do I program a slackbot to send a regular message automatically every week

I am building a slackbot that will remind people in my organisation to perform certain admin (hours expenses etc) every week. I know this can be very easily done by each person creating a recurring reminder. What i want is to create a bot that will send a preconfigured message to people every week. I've looked online extensively, and haven't yet found out how slackbot can send a message without an event or being otherwise prompted.
I'm currently testing this on a local ngrok server with the following backend:
const { WebClient } = require('#slack/web-api');
const { createEventAdapter } = require('#slack/events-api');
const slackSigningSecret = process.env.SLACK_SIGNING_SECRET;
const slackToken = process.env.SLACK_TOKEN;
const port = process.env.SLACK_PORT || 3000;
const slackEvents = createEventAdapter(slackSigningSecret);
const slackClient = new WebClient(slackToken);
slackEvents.on('app_mention', (event) => {
console.log(`Got message from user ${event.user}: ${event.text}`);
(async () => {
try {
await slackClient.chat.postMessage({ channel: event.channel, text: `Hello <#${event.user}>! Have you completed your Time sheets for this week yet?` })
} catch (error) {
console.log(error.data)
}
})();
});
slackEvents.on('error', console.error);
slackEvents.start(port).then(() => {
console.log(`Server started on port ${port}`)
});
Once this reminder is done, i intend to build upon it (more features, just need a beginning) so please don't recommend alternative ways my organisation can send reminders to people.
You can try using the chat.scheduleMessage method instead (https://api.slack.com/methods/chat.scheduleMessage). Since you won't rely on an event you may want to store the necessary conversations ids so that they're ready when the app needs to call the method.

Google Play Store internal test - app stuck on splash screen

I have created an internal test for an app using the Google Play Console and sent the hyperlink to a test user. However, once the app is installed on the tester's phone and the Open button is tapped it gets stuck on the splash screen and will not go any further. The tester has tried restarting the phone, Force Stop the Google Play app, Clear Data and Clear Cache for Google Play app, uninstall/reinstall the app. None of these have helped. What would cause this behavior? What steps should I take next to debug/resolve this issue?
i solved my problem by putting try block before runApp(MyApp()) in main
void main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
final InitialController _initialController = Get.put(InitialController(), permanent: true);
final BasketController _basketController = Get.put(BasketController(), permanent: true);
//final BackInterceptorController _backInterceptorController = Get.put(BackInterceptorController(), permanent: true);
await _initialController.tokenInit();
} catch (e) {
logger(e);
}
runApp(MyApp());
}

TokBox screen sharing audio is not working

I'm using the TokBox / OpenTok screen sharing API for web browser, and when publishing a screen I'm using "publishAudio: true", but the subscriber does not receive any audio. The subscriber does receive the screen video though.
Does anyone know how to solve this audio issue? I'm using Google Chrome on macOS Catalina.
I need see more of you concrete case code but i hope this can help you.
You need to send the audioSource. Example:
if (videoSource) { // in my case, i'm using null or 'screen'
opts.videoSource = videoSource;
}
console.log('micStream getAudioTracks:');
console.log(micStream.getAudioTracks());
opts.audioSource = micStream.getAudioTracks()[0]; //you can choose you audio source
const target = document.getElementById(targetId);
const pub = OT.initPublisher(target, opts, err => {
if (err) {
console.log('err');
reject(err);
} else {
console.log('resolve');
resolve(pub);
}
});
I

Why does QnAMaker Bot does not work in Azure Web Chat channel but works locally

I was able to convert my EchoBot to interact with QnAMaker as per instructions here on my local development system but when I publish the same using kudu repo (tried using Azure DevOps service Ci/CD pipeline but it does not work [in preview] because after deployment the bot just hangs on portal and never able to test it on web chat.. so gave up and used recommended kudu repo), I do not get the correct answer to my response. For every question I send, it is unable to detect the QnAMaker service. And I am returning error message from the code that says no QnaMaker answer was found.
How do I troubleshoot to identify the cause of this?
My bot file seems to be working fine locally and I am able to get the answer from QnAMaker locally but not after publishing the code to my Web App Bot in Azure.
I feel like Botframework V4 (using .net) is not very straight forward and the instruction on the portal (document) is still kind of evolving or sometime incomprehensible.
Here is the snapshot from my emulator while testing the chat locally:
And here is the snapshot of production endpoint (using the same questions on portal) with my error msg from OnTurnAsync function:
My .bot has all the services defined and local bot is working fine.
This is the code in my ChatBot class:
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
// Handle Message activity type, which is the main activity type for shown within a conversational interface
// Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
if (turnContext.Activity.Type == ActivityTypes.Message)
{
// Get the conversation state from the turn context.
var state = await _accessors.CounterState.GetAsync(turnContext, () => new CounterState());
// Bump the turn count for this conversation.
state.TurnCount++;
// Set the property using the accessor.
await _accessors.CounterState.SetAsync(turnContext, state);
// Save the new turn count into the conversation state.
await _accessors.ConversationState.SaveChangesAsync(turnContext);
// Echo back to the user whatever they typed.
//var responseMessage = $"Turn {state.TurnCount}: You sent '{turnContext.Activity.Text}'\n";
//await turnContext.SendActivityAsync(responseMessage);
// QnAService
foreach(var qnaService in _qnaServices)
{
var response = await qnaService.GetAnswersAsync(turnContext);
if (response != null && response.Length > 0)
{
await turnContext.SendActivityAsync(
response[0].Answer,
cancellationToken: cancellationToken);
return;
}
}
var msg = "No QnA Maker answers were found. Something went wrong...!!";
await turnContext.SendActivityAsync(msg, cancellationToken: cancellationToken);
}
else
{
await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected");
}
}

Telegram Bot Random Images (How to send random images with Telegram-Bot)

const TeleBot = require('telebot');
const bot = new TeleBot({
token: 'i9NhrhCQGq7rxaA' // Telegram Bot API token.
});
bot.on(/^([Hh]ey|[Hh]oi|[Hh]a*i)$/, function (msg) {
return bot.sendMessage(msg.from.id, "Hello Commander");
});
var Historiepics = ['Schoolfotos/grr.jpg', 'Schoolfotos/boe.jpg',
'Schoolfotos/tobinsexy.jpg'];
console.log('Historiepics')
console.log(Math.floor(Math.random() * Historiepics.length));
var foto = Historiepics[(Math.floor(Math.random() * Historiepics.length))];
bot.on(/aap/, (msg) => {
return bot.sendPhoto(msg.from.id, foto);
});
bot.start();
The result I'm getting from this is just one picture everytime, but if I ask for another random picture it keeps showing me the same one without change.
I recently figured this out, so I'll drop an answer for anyone that runs into this issue.
The problem is with Telegram's cache. They cache images server side so that they don't have to do multiple requests to the same url. This protects them from potentially getting blacklisted for too many requests, and makes things snappier.
Unfortunately if you're using an API like The Cat API this means you will be sending the same image over and over again. The simplest solution is just to somehow make the link a little different every time. This is most easily accomplished by including the current epoch time as a part of the url.
For your example with javascript this can be accomplished with the following modifications
bot.on(/aap/, (msg) => {
let epoch = (new Date).getTime();
return bot.sendPhoto(msg.from.id, foto + "?time=" + epoch);
});
Or something similar. The main point is, as long as the URL is different you won't receive a cached result. The other option is to download the file and then send it locally. This is what Telebot does if you pass the serverDownload option into sendPhoto.

Resources