Alexa: Elicit slots after DelegateDirective - alexa

I am running into issues when trying to elicit a slot after delegating to a new intent.
I have an intent called EnterPIN which handles conversation flow surrounding PIN entry for account linking. It checks if they have account linked, and if so asks for PIN, and otherwise tells them how to account link.
The desired result would be to delegate to this intent any time PIN is required, and pass along the previous intent so it can return after authentication is done.
When I delegate to EnterPIN, I am not able to fill the PIN slot even after eliciting the slot on the current intent. However, when I directly invoke the EnterPIN intent through an utterance like 'sign me in' then the slot's are elicited correctly and it accepts my PIN on the next request.
CallContactCentre.js (snippet):
return handlerInput.responseBuilder
.addDelegateDirective({name: 'EnterPIN', slots: {
"OBFUSCATE_PIN": {
"name": "OBFUSCATE_PIN",
"confirmationStatus": "NONE"
}
}})
.withShouldEndSession(false)
.getResponse();
EnterPIN.js:
module.exports = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
console.log('request.intent', request.intent);
return request.type === 'IntentRequest'
&& request.intent.name === 'EnterPIN'
&& request.intent.slots
&& request.intent.slots.OBFUSCATE_PIN
&& request.intent.slots.OBFUSCATE_PIN.value === undefined
&& handlerInput.attributesManager.getSessionAttributes().PIN === undefined
},
handle(handlerInput) {
const requestAttributes = handlerInput.attributesManager.getRequestAttributes();
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
if(handlerInput.requestEnvelope.session.user.accessToken !== undefined) {
return handlerInput.responseBuilder
.speak('You have account linked. Please enter your PIN code')
.reprompt(requestAttributes.t('PROMPT'))
.addElicitSlotDirective('OBFUSCATE_PIN')
.withShouldEndSession(false)
.getResponse();
} else {
return handlerInput.responseBuilder
.speak('You have not account linked. Please find this skill in the Alexa directory and enable account linking')
.reprompt(requestAttributes.t('PROMPT'))
.addElicitSlotDirective('OBFUSCATE_PIN')
.withShouldEndSession(false)
.getResponse();
}
},
};
Direct invocation:
requestEnvelope.request.intent = { name: 'EnterPIN', confirmationStatus: 'NONE',
slots: {
OBFUSCATE_PIN: {
name: 'OBFUSCATE_PIN',
value: '1234',
confirmationStatus: 'NONE',
source: 'USER'
}
}
}
Delegate Directive:
requestEnvelope.request.intent = { name: 'EnterPIN', confirmationStatus: 'NONE',
slots: {
OBFUSCATE_PIN: {
name: 'OBFUSCATE_PIN',
confirmationStatus: 'NONE',
source: 'USER'
}
}
}
As you can see, we get a value for OBFUSCATE_PIN when going through the direct invocation, but when reaching the intent from a delegate directive, the value is not being set.
Any information that could lead to the fix of this issue is much appreciated.
Thanks

I think you may need to include "value" when you create the new intent in delegateDirective.
return handlerInput.responseBuilder
.addDelegateDirective({name: 'EnterPIN', slots: {
"OBFUSCATE_PIN": {
"name": "OBFUSCATE_PIN",
"confirmationStatus": "NONE",
"value": "" <-----------
}
}})
.withShouldEndSession(false)
.getResponse();

Related

Adding buttons to an application sent to specified applicationChannelId

Yes I know TLDR but I would appreciate the help
Ok I have this wall of code below I use for applications
It uses a button to start the application (asking questions)
and after the application is filled in it sends that application to a specified applicationChannelId
is there any way I could add buttons to the application that was sent to the applicationChannelId to accept or deny members?
Accept would add a role by id and sends a message to the original applicant
//Not the code I tried using just an example for what the Accept button would do
//
let teamRole = message.guild.roles.cache.find(role => role.id == "761996603434598460")
member.roles.add(teamRole)
member.send("You have been accepted into the team")
Deny would send a message to the original applicant
I have tried doing this for the past few days but just can't get it to work it either does nothing or breaks everything
I have removed some info from the code below to make it shorter
Code for my button I already use to start the application for an applicant
client.on("message", async (message) => {
const reqEmbed = {
color: 0xed5181,
title: 'Blind Spot Team Requirements',
url: 'link',
author: {
name: '',
icon_url: '',
url: '',
},
description: '',
thumbnail: {
url: '',
},
fields: [{
"name": `Read through these Requirements`,
"value": `- requirments will go here`,
}, ],
image: {
url: '',
},
footer: {
text: 'Blind Spot est 2019',
icon_url: 'link',
},
};
//
// Don't reply to bots
let admins = ['741483726688747541', '741483726688747541'];
if (message.content.startsWith(`#blindspot`)) {
message.delete();
const amount = message.content.split(" ")[1];
if (!admins.includes(message.author.id)) {
message.reply("You do not have permission to do that!");
return;
}
// Perform raw API request and send a message with a button,
// since it isn't supported natively in discord.js v12
client.api.channels(message.channel.id).messages.post({
data: {
embeds: [reqEmbed],
components: [{
type: 1,
components: [{
type: 2,
style: 4,
label: "Apply",
// Our button id, we can use that later to identify,
// that the user has clicked this specific button
custom_id: "send_application"
}]
}]
}
});
}
});
Rest of code that handles questions and sends application to applicationChannelId when complete
// Channel id where the application will be sent
const applicationChannelId = "652099170835890177";
// Our questions the bot will ask the user
const questions = ["These are the questions but have deleted them to make this shorter",];
// Function that will ask a GuildMember a question and returns a reply
async function askQuestion(member, question) {
const message = await member.send(question);
const reply = await message.channel.awaitMessages((m) => {
return m.author.id === member.id;
}, {
time: 5 * 60000,
max: 1
});
return reply.first();
}
client.ws.on("INTERACTION_CREATE", async (interaction) => {
// If component type is a button
if (interaction.data.component_type === 2) {
const guildId = interaction.guild_id;
const userId = interaction.member.user.id;
const buttonId = interaction.data.custom_id;
const member = client.guilds.resolve(guildId).member(userId);
if (buttonId == "send_application") {
// Reply to an interaction, so we don't get "This interaction failed" error
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: "I have started the application process in your DM's.",
flags: 64 // make the message ephemeral
}
}
});
try {
// Create our application, we will fill it later
const application = new MessageEmbed()
.setTitle("New Application")
.setDescription(`This application was submitted by ${member}/${member.user.tag}`)
.setFooter("If the #Username doesn't appear please go to general chat and scroll through the member list")
.setColor("#ED4245");
const cancel = () => member.send("Your application has been canceled.\n**If you would like to start your application again Click on the Apply button in** <#657393981851697153>");
// Ask the user if he wants to continue
const reply = await askQuestion(member, "Please fill in this form so we can proceed with your tryout.\n" + "**Type `yes` to continue or type `cancel` to cancel.**");
// If not cancel the process
if (reply.content.toLowerCase() != "yes") {
cancel();
return;
}
// Ask the user questions one by one and add them to application
for (const question of questions) {
const reply = await askQuestion(member, question);
// The user can cancel the process anytime he wants
if (reply.content.toLowerCase() == "cancel") {
cancel();
return;
}
application.addField(question, reply);
}
await askQuestion(member, "Would you like to submit your Application?\n" + "**Type `yes` to get your Application submitted and reviewed by Staff Members.**");
// If not cancel the process
if (reply.content.toLowerCase() != "yes") {
cancel();
return;
}
// Send the filled application to the application channel
client.channels.cache.get(applicationChannelId).send(application);
} catch {
// If the user took too long to respond an error will be thrown,
// we can handle that case here.
member.send("You took too long to respond or Something went wrong, Please contact a Staff member\n" + "The process was canceled.");
}
}
}
});
at this point I just feel like not even doing this and keep it as is because its driving me insane
You very well can! just send it as you send your normal buttons!
const {
MessageButton,
MessageActionRow
} = require("discord.js"),
const denybtn = new MessageButton()
.setStyle('DANGER')
.setEmoji('❌')
.setCustomId('deny')
const acceptbtn = new MessageButton()
.setStyle('SUCCESS')
.setEmoji('✔')
.setCustomId('accept')
client.channels.cache.get(applicationChannelId).send({
embeds: [application],
components: [new MessageActionRow().addComponents["acceptbtn", "denybtn"]]
});
const collector = msg.createMessageComponentCollector({
time: 3600000,
errors: ["time"],
});
await collector.on("collect", async (r) => {
if (r.user.id !== message.author.id)
return r.reply({
content: "You may not accept/ deny this application",
ephemeral: true,
});
if (r.customId === "acceptbtn") {
let teamRole = message.guild.roles.cache.find(role => role.id == "761996603434598460")
member.roles.add(teamRole)
member.send("You have been accepted into the team")
}
if (r.customId === "denybtn") {
member.send("You have been rejected");
}
});
NOTE: Please be mindful that since your question lacks the functions / method definitions you are using I have used discord.js v13's methods, you may update your discord.js version and the code will work as intended ALTHOUGH the component collector's functions have been directly copy pasted from your question and in some instances such as member#send member is not defined, so please take this as an example and I urge you to write the code instead of copy pasting directly!

Discord.js DiscordAPIError: Missing Permissions ---Which permission is missing?

I have a bot which is supposed to create a channel under a specific category and then add two users to this channel.
The following bit of code is "supposed" to work and add user two, but fails with DiscordAPIError: Missing Permissions.
What I can't figure out is the actual permission required for this?
function addUserToChannel(ch, user, altCh) {
console.log(user.username,"sendmsg",ch.permissionsFor(client.user).has("MANAGE_CHANNELS", false)); //returns true
if (!ch.permissionsFor(user).has("SEND_MESSAGES", false)) {
console.log("User", user.username, "lacks view-channel permission");
ch.updateOverwrite(user, { //fails here obviously
SEND_MESSAGES: true,
VIEW_CHANNEL: true
});
} else {
console.log("WARN:", user.username, " already in channel ", ch.name);
altCh.send(user.toString() + " join conversation here: " + ch.toString());
}
}
The channel is created using the following code:
function createPrivateChannel(guild, convo, user) {
let everyoneRole = guild.roles.cache.find(r => r.name === "#everyone");
let parent = guild.channels.cache.find(ch => {
//console.log(ch.id,secret.convoCat.id);
return ch.id == secret.convoCat.id;
});
return guild.channels.create(convo.chName, {
type: "text",
parent: parent,
permissionOverwrites: [
{
id: everyoneRole.id, //private channel
deny: ["VIEW_CHANNEL", "SEND_MESSAGES"]
},
{
id: client.user.id, //bot permissions
allow: [ "VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY", "MANAGE_CHANNELS" ]
},
{
id: user.user.id, //a different user
allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"]
}
]
});
}
According to the Discord documentation for the 'Edit Channel Permissions' route (which is what updateOverwrite ultimately uses):
Requires the MANAGE_ROLES permission. Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel).

how to translate discord.js decimals?

so basically what i wanted is to make the bot send a message in the serverLogs channel whenever a channel in that guild is deleted. The message sends general information about the deleted channel, but i wanted to expand this embed to make it say what permission overwrites dide that channel have so i tried console logging it to see what kind of info i get.
client.on('channelDelete', (channel) => {
if(channel.type === 'dm') return;
const serverLogs = channel.guild.channels.cache.get(serverLog);
if (typeof serverLogs !== 'undefined') {
const embed = new Discord.MessageEmbed()
.setColor('#DB0000')
.setTimestamp()
.setTitle('Channel Deleted')
.addFields(
{ name:'name', value:channel.name, inline: false },
{ name:'Category', value:channel.parent, inline: false },
{ name:'created at', value:`${moment(channel.createdAt).format('MMMM Do YYYY, h:mm:ss a')}`, inline: false },
{ name:'ID', value: channel.id, inline: false },
);
serverLogs.send(embed);
// YOU CAN IGNORE ALL OF THE ABOVE
channel.permissionOverwrites
.each(E=>console.log(`<#${E.id}>`))
.each(E=>console.log(E.deny))
.each(E=>console.log(E.allow));
/*output
<#/*id here hehe*/>
Permissions { bitfield: 16 } //wtf is 16
Permissions { bitfield: 1024 }// wtf is 1024
*/
}
});
Is there a way to translate these decimals to normal permission Flags so i can read and manipulate them easier
You can translate bitfield permissions into flags easily
console.log(new Discord.Permissions(16).toArray());
// Output in console:
// [ 'MANAGE_CHANNELS' ]
Where the "16" is, that is where you would put the bitfield number.

Ban Command in Discord.js won't Compile

I have a command which bans a user. I have tried changing the last part to several different variations yet if I try modChannel.message.send, it throws the error "modChannel already defined." I'm not sure what else to do.
module.exports = {
name: "ban",
description: "Ban the troublesome users!",
execute(message, args) {
let member = message.mentions.user.first();
if(!message.member.roles.some(r=>["Administrator"].includes(r.name))) {
return message.channel.send("You don't have the permissions to use this command!");
}
if(!member.bannable) {
return message.channel.send("I can\'t ban this person. Please try again. Make sure I have ban permissions.");
}
let reason = args.slice(7).join(" ");
if(!reason) {
reason = "No reason was provided.";
}
let modChannel = client.guilds.find(ch => ch.name === "mod-log");
const banEmbed = {
color: 225,
title: "User Banned",
description: `**User**: ${member.username}#${member.discriminator} (${member.id})
**Reason**: ${reason}
**Banned By**: ${message.author.username}#${message.author.discriminator}`,
},
modChannel.send({embed: banEmbed });
},
};
Try:
let modChannel = message.guild.channels.find(c => c.name === "logs)

How to ask location permission in react native.60?

I also added
Fine.Location permission to line in minifest.Xml file but nothing happen. My targetsdkverion =28.
Please suggest me a solution
you should use react-native-geolocation-service and get permissions according to platform. On android you need to request permission on your own like bellow:
if (Platform.OS !=='android' )
Geolocation.requestAuthorization()
else {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'we need GPS location service',
message:
'we need location service to provide your location',
// buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
} else {
Defaults.modal.current.renderModel(modalOptions);
return false;
}
}
catch (err) {
console.warn(err);
}
}

Resources