diff --git a/freepbx.js b/freepbx.js index 73cf5d9..1dd6c2d 100644 --- a/freepbx.js +++ b/freepbx.js @@ -176,11 +176,11 @@ class FreepbxManager { } // TODO: Implement updateName method, Current implementation resets extension for some reason - async updateExtPassword(ext, password) { + async updateExtPassword(ext, oldName, password) { const query = gql` mutation updateExt($ext: ID!, $name: String, $password: String) { updateExtension(input: { - name: test + name: $name extensionId: $ext extPassword: $password }) { @@ -190,7 +190,8 @@ class FreepbxManager { }`; const variables = { ext, - password + password, + name: oldName }; return await this.pbxCall(query, variables); } diff --git a/interactionHandlers/modals/resetPasswordModal.js b/interactionHandlers/modals/resetPasswordModal.js index 835d05d..7e6ea1d 100644 --- a/interactionHandlers/modals/resetPasswordModal.js +++ b/interactionHandlers/modals/resetPasswordModal.js @@ -16,6 +16,7 @@ module.exports.execute = async (interaction) => { // console.log(JSON.stringify(interaction, null, 2)); const newPassword = interaction.fields.getTextInputValue('newPassword'); let passwordToSet = newPassword; + let oldName = extData.fetchExtension.user.name; if (!newPassword || newPassword.trim() === '') { // Generate password based on process.env.PASSWORD_LENGTH and process.env.PASSWORD_CHARS or default to 32 alphanumeric with caps const length = parseInt(process.env.PASSWORD_LENGTH) || 32; @@ -23,8 +24,8 @@ module.exports.execute = async (interaction) => { passwordToSet = Array.from({ length }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join(''); } try { - //const updated = await fpbx.updateExtPassword(lookup.extension, passwordToSet); - const updated = await fpbx.updateExtName(lookup.extension, passwordToSet); + const updated = await fpbx.updateExtPassword(lookup.extension, oldName, passwordToSet); + //const updated = await fpbx.updateExtName(lookup.extension, passwordToSet); console.log(updated) await interaction.editReply({ content: `Your extension password has been reset successfully! Your new password is: ||\`${passwordToSet}\`||`, ephemeral: true }); } catch (error) {