Created
June 29, 2018 12:22
-
-
Save Bigomby/b4ba451a2f9bf9ee2307102fe99ee985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Wallet, Chat, Identity } from './'; | |
import { RequestSigner } from './request-signer'; | |
import { MemorySignalStore } from './signal-account/stores/memory-signal-store'; | |
import { SignalAccount } from './signal-account'; | |
const chatUrl = 'https://chat.development.service.toshi.org'; | |
const identityUrl = 'https://identity.development.service.toshi.org'; | |
function createMessage(destinationRegistrationId: number, destination: string) { | |
return { | |
destination, | |
timestamp: Math.floor(Date.now() / 1000), | |
destinationRegistrationId, | |
destinationDeviceId: 1, | |
content: 'Hello world', | |
body: 'Hi there', | |
}; | |
} | |
(async () => { | |
const wallet = Wallet.generate(); | |
const requestSigner = new RequestSigner(wallet); | |
const signalAccount = await SignalAccount.bootstrap(); | |
const chat = new Chat({ url: chatUrl, requestSigner, signalAccount }); | |
const identity = new Identity(requestSigner, { url: identityUrl }); | |
try { | |
const address = wallet.getAddress(); | |
await chat.account.register(address); | |
const { toshi_id } = await identity.user.get('bigombytest'); | |
const bundle = await chat.keys.getBundle(address, toshi_id); | |
const res = await chat.message.send(address, toshi_id, createMessage( | |
8282, | |
toshi_id, | |
) as any); | |
console.log(res.data); | |
} catch (e) { | |
console.error(e.response); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment