I have working on google actions lately. I need to play an url of mp3 for x minute(this receive from user such as play abc for 30 minutes.). My problem is my mp3 url is only 1.30 minutes long. How can I play it until x minutes. I use dialogflow index.js file for code. Here is what I try
app.intent('soundplay', (conv, {soundreq, duration}) => {
conv.ask(new Suggestions('Exit'));
conv.ask(new SimpleResponse({
speech: 'xxx',
text: 'xxx',
}));
conv.ask(sound);
var d = duration.milliseconds;
setTimeout(sound, d);
});
I try to use setTimeout but it also doesn't work.
There are a few issues you need to deal with.
The first is that sound is pretty vague from your code sample. You're using it in setTimeout(), which suggests that it is a function, but you're also passing it to conv.ask() which suggests it is a MediaResponse or some other object.
The second is that this code will run on your server, not on the user's device, and Actions work in a conversational back-and-forth model. So once you send something to the user, you need to wait until the user (or the user's device) sends you another message that you can reply with.
The solution is to include a MediaObject as part of the response you build. This will include the URL of the audio you want to play, along with a title and some other information.
When the audio finishes playing, your Dialogflow agent will get a message with an actions_intent_MEDIA_STATUS Event. You can create an Intent that handles this event and, in the Intent Handler for it in your webhook, check to see if the time has expired. If it has, you can prompt for what to do now or end the conversation or whatever is appropriate. If it has not expired, you can play the audio again using another MediaObject.
Related
I have chat bot, I build it with bot framework nodejs SDK I integrate this chat bot to whatsapp and I want to display some buttons in the whatsapp chat,
So is there any one found a solution for this problem pleas help me
Note: I try to send a hero card but I run to problem
Error: TwilioWhatsAppAdapter.parseActivity():
An activity text or attachment with contentUrl must be specified.
I don't know how bot framework attempts to send WhatsApp messages with buttons, but I doubt it fits with the way Twilio wants to send them.
Currently, to send a message with buttons, you need to register and use a template message. When you send the text of a message that matches one of your templates, then Twilio will deliver the entire template with buttons as well.
For the future, look out for the Twilio Content API which will streamline templates, buttons and other rich messages across platforms.
It looks like you are using the TwilioWhatsAppAdapter from the botbuilder-community-js repo.
Looking at the adapter's code, it doesn't appear to be configured to handle any card other than a 'signin' card (see here). If you don't mind doing a little leg work on this, I don't see why you couldn't fork this repo and build in functionality that supports a hero card similar to the signin implementation.
I imagine it would look something like this:
case 'application/vnd.microsoft.card.hero':
// eslint-disable-next-line no-case-declarations
const hero = attachment.content;
message.body = `${ hero.text }\n\n`;
message.body += (hero.buttons[0].title ? `*${ hero.buttons[0].title }*\n` : '');
message.body += hero.buttons[0].value;
break;
The above may need a little massaging but it wouldn't be far off from this. Then, you just need to build the library for use.
I have made a custom discord bot for a fan server, which is hosted by Heroku so it can stay online when I'm not. What I want to do is to have the bot play an mp3 file from its folder when someone gives a specific command for it, but I want the music to play in a specific voice channel.
First, I tried treating it, the same as an image file. For example:
if (message.content == "Play the Funky Tune.")
{
message.reply("Of course, I hope you enjoy!", { files: ["./Music/FunkyTune.mp3"] });
}
However this causes the bot to put the music file there, and while you can click on it and play it, the moment you click on another channel, the music is paused. I want it to play the song in a specific voice channel so that it continues playing when the user clicks on another channel.
When doing research for this, every topic is always asking for a YouTube video link, which converts it into audio, but this is not what I want, since anything can happen to YouTube videos.
P.S. I am not interested in using already made bots, I want to integrate this music feature into my own bot.
if (message.content == "Play the Funky Tune.") {
// Checking if the message author is in a voice channel.
if (!message.member.voice.channel) return message.reply("You must be in a voice channel.");
// Checking if the bot is in a voice channel.
if (message.guild.me.voice.channel) return message.reply("I'm already playing.");
// Joining the channel and creating a VoiceConnection.
message.member.voice.channel.join().then(VoiceConnection => {
// Playing the music, and, on finish, disconnecting the bot.
VoiceConnection.play("./Music/FunkyTune.mp3").on("finish", () => VoiceConnection.disconnect());
message.reply("Playing...");
}).catch(e => console.log(e))
};
Note that you must run the following commands in order for this to work:
npm install ffmpeg-static
npm install #discordjs/opus
I have a webchat for a user connected to the bot through directline.
I want a second user to join to the same conversation, but I want the second user to be able to read the full conversation.
Right now when the second user connects to the conversation it doesn't see anything of the first user conversation because he doesn't join with a watermark value.
I have this code on bot builder v4 right now:
const options = {
method: 'GET',
uri: 'https://myuri/addRow?conversationId='+stepContext.context.activity.conversation.id,
};
await req-promise(options);
I would like to send something like this:
const options = {
method: 'GET',
uri: 'https://myuri/addRow?conversationId='+stepContext.context.activity.conversation.id+'watermark='+watermark,
};
await req-promise(options);
Is there anyway to get that watermark value?
Thanks
Per this GitHub issue.
The cache of messages in the Direct Line connector service is intended to be used as a connection reliability mechanism, not as an actual message history store.
If you require more granular control over conversation history, you will need implement an a transcript store server side. And, you can use the SendConversationHistoryAsync api to send chunks of history messages to the conversation.
We do not currently have a complete example demonstrating this, but it is in the works.
I would recommend using a transcript logger to store and manage your own conversation history instead of trying to pull the messages from the cache. Also, if you try to use the watermark, you'll run into permission issues since one conversation doesn't have the ability to see another conversation's data.
Hope this helps!
Is it possible to format a conversation so that the bot initiates conversation using dialogflow in a web demo integration?
The objective is to say something like “Hi, I’m a bot, I can do x” to establish that it’s a chatbot rather than a human.
Can anyone suggest any idea for this?
You can set a welcome intent, then send a /query request containing an event parameter. Set the event parameter to WELCOME and your chatbot will respond with whatever conversation opening you set.
More info here: https://dialogflow.com/docs/events
If you are using something other than the API for interacting with your Dialogflow agent (Slack, Facebook Messenger, etc.) you will need to add an appropriate event under "intents" in your console (such as the "Facebook Welcome" event).
For interacting with your Dialogflow agent via the API, see below.
In the API interaction quickstart documentation, Dialogflow gives you the SessionClient's detectIntent method for sharing messages with your bot.
Each language has a different solution. But on an abstract level, you want to change the request object that you send to Dialogflow to include a "Welcome" event (no input message required), as Omegastick described.
For example, in Node.js, your request object would look like this:
// The text query request.
const request = {
session: sessionPath,
queryInput: {
event: {
name: "Welcome",
languageCode: languageCode
}
},
};
This assumes you have an appropriate intent set up in your Dialogflow console to handle Welcome events. One is provided by default that you can observe.
You can also add contexts, so that your agent gives a different greeting message based on some condition.
Hello i'm newbie and im hardly to understand this notification in service-worker, and because my knowledge isn't good yet then probably i will unable to explain my problem clearly.
so here's the code :
// triggered everytime, when a push notification is received.
self.addEventListener('push', function(event) {
console.info('Event: Push');
var title = 'New commit on Github Repo: RIL';
var body = {
'body': 'Click to see the latest commit',
'tag': 'pwa',
'icon': './images/48x48.png'
};
event.waitUntil(
self.registration.showNotification(title, body)
);
});
this is the code that trigger to POP the notification, what I do not understand is where the argument to accept/ receive the data ?
I've been searched a lot: https://auth0.com/blog/introduction-to-progressive-web-apps-push-notifications-part-3/ ,
https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web
there's some new data JSON or from git-server or push api, but I still hardly to understand where's to accept the data.
sorry if you still do not understand what's my problem.
Here to make it simple what I want :
Let's say i make a button, and everytime i click the button it will value as 'True' and I want that 'True' value to pass into argument and trigger the push of notication in service-worker.
2nd questions: am I able to trigger notification with header or text in html ? since we can manipulate the text with DOM ?
am I able to trigger notification without GCM, or API cause I just want a simple notification in serivce-worker like above without passing much data.
If you give more advice or maybe notification without service-worker but real time , I am surely happy to read it but I hope Im able to understand.
There are basically two concepts involved that work well together but can be used independently. The first is the visible UI shown to a user that tells them information or prompts them for an action. The second is sending an event from a server to the browser without requiring the user to currently be active on the site. For full details I recommend reading Google's Web Push docs.
Before either of those scenarios you have to request permission from the user. Once permission is granted you can just create a notification. No server or service worker required.
If you want to send events from a server you will need a service worker and you will need to get a subscription for the user. Once you have a subscription you would send it to a server for when you want to send an event to that specific browser instance.
Once you receive a push event from a server you display the UI the same as in the first scenario except you have to do it from the service worker.