Skip to content

Instantly share code, notes, and snippets.

@sungkhum
Created January 29, 2024 16:35
Show Gist options
  • Save sungkhum/6946b180b36f251282d648fd5f979120 to your computer and use it in GitHub Desktop.
Save sungkhum/6946b180b36f251282d648fd5f979120 to your computer and use it in GitHub Desktop.
How to send a new direct message with Deso-protocol js
// Using https://github.com/deso-protocol/deso-js
//////////////////////////////
// Derived Key looks like this:
//////////////////////////////
if (
!identity.hasPermissions({
TransactionCountLimitMap: {
NEW_MESSAGE: "UNLIMITED"
},
})
) {
// if the user doesn't have permissions, request them
// and abort the submit
await identity.requestPermissions({
GlobalDESOLimit: 10000000, // 0.01 DESO
TransactionCountLimitMap: {
NEW_MESSAGE: "UNLIMITED"
},
});
// Code that sends a message - in this case the receiptient is hard-coded - ignore the isHuman.
const sendErrorReport = () => {
// Construct the full message to send
const messageToSend = userInput;
setModalErrorReportSentComplete('');
setModalIsSendingErrorReport(true);
const sendMessageParams = {
SenderPublicKeyBase58Check: currentUser.PublicKeyBase58Check,
RecipientPublicKeyBase58Check: "BC1YLisKA2eNbmgf749g4RV9M3pis2jFu2FhuohnikfEPK85VtCpDPT",
Message: messageToSend, // Use the message from the modal
AccessGroup: 'default-key',
};
sendMessage(sendMessageParams)
.then(response => {
console.log('Message sent successfully:', response);
setModalIsSendingErrorReport(false);
setModalErrorReportSent(true);
setShowErrorModal(false);
setModalErrorReportMessage('');
setUserInput('')
setModalErrorReportSentComplete('Message sent successfully! Thank you!');
// Reset the success message state after a few seconds
setTimeout(() => {
setModalErrorReportSent(false);
console.error('Timout sending message.');
setModalIsSendingErrorReport(false);
setModalErrorReportMessage('');
setUserInput('')
setModalErrorReportSentComplete('The message timed out. Please try again later.');
}, 10000);
})
.catch(error => {
console.error('Error sending message:', error);
setModalIsSendingErrorReport(false);
// Optionally handle error display in the UI
setModalErrorReportMessage('');
setUserInput('')
setModalErrorReportSentComplete('Error sending message. Please try again later.');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment