Skip to content

Instantly share code, notes, and snippets.

@Bigomby
Created June 29, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bigomby/b4ba451a2f9bf9ee2307102fe99ee985 to your computer and use it in GitHub Desktop.
Save Bigomby/b4ba451a2f9bf9ee2307102fe99ee985 to your computer and use it in GitHub Desktop.
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