﷽
A unified platform to manage MSOCIETY community.
This project is rewritten to Typescript from Go: https://gitlab.com/msociety/msocietybot
- Run
npm i
command - Copy
env.sample
to.env
- Setup database settings inside
.env
file - Create new bot and add token to
.env
file - Run
npm start
command
You can turn on debug (verbose) logging via supplying the env DEBUG
:
$ DEBUG=telegraf:client,msocietybot npm run start
$ docker-compose up
$ npm run test
Migration scripts can be automatically generated by TypeORM:
$ npm run create-migration {migrationName}
It will work correctly as long as you have a db running with the latest migrations applied. TypeORM will calculate the differences using the schema to generate the new migrations.
Due to an issue with TypeORM (sqlite) when doing recursive relationships (e.g. Message -> Message), the syncronize
flag does not work and hence we have to also use migration scripts for testing:
$ npm run test:create-initial-migration
Then, ensure any lines related to temporary_messages
are removed in the generated migration:
// up(queryRunner: QueryRunner)
await queryRunner.query(`CREATE TABLE "temporary_messages" ("id" bigint NOT NULL, "unixtime" bigint NOT NULL, "last_edit" datetime, "edit_history" text, "album_id" varchar, "signature" varchar, "text" varchar, "payload" varchar, "entities" text, "caption" varchar, "caption_entities" text, "audio" text, "document" text, "animation" text, "game" text, "photo" text, "sticker" text, "voice" text, "video_note" text, "video" text, "contact" text, "location" text, "venue" text, "new_group_title" varchar, "new_group_photo" text, "group_photo_deleted" boolean, "group_created" boolean, "supergroup_created" boolean, "channel_created" boolean, "forward_signature" varchar, "forward_date" datetime, "media_group_id" varchar, "author_signature" varchar, "invoice" text, "successful_payment" text, "connected_website" varchar, "passport_data" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" datetime, "sender_id" bigint, "reply_to_message_id" bigint, "chat_id" bigint NOT NULL, "user_joined_id" bigint, "user_left_id" bigint, "migrate_to_chat_id" bigint, "migrate_from_chat_id" bigint, "pinned_message_id" bigint, "pinned_message_chat" bigint, "forward_from_id" bigint, "forward_from_chat_id" bigint, "forward_from_message_id" bigint, "forward_from_message_chat" bigint, CONSTRAINT "FK_22133395bd13b970ccd0c34ab22" FOREIGN KEY ("sender_id") REFERENCES "user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_7f87cbb925b1267778a7f4c5d67" FOREIGN KEY ("reply_to_message_id") REFERENCES "messages" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_7540635fef1922f0b156b9ef74f" FOREIGN KEY ("chat_id") REFERENCES "chats" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_a68c86f2ff7e0a7dbfb2dcc9a65" FOREIGN KEY ("user_joined_id") REFERENCES "user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_4eec01b11cb4f66e2b49dd21947" FOREIGN KEY ("user_left_id") REFERENCES "user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_54e96628c7652cf412c39828156" FOREIGN KEY ("migrate_to_chat_id") REFERENCES "chats" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_5799250bd7acc0eeda514e80646" FOREIGN KEY ("migrate_from_chat_id") REFERENCES "chats" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_7f81219c47b09bd26197d253b8c" FOREIGN KEY ("pinned_message_id", "pinned_message_chat") REFERENCES "messages" ("id", "chat_id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_8298d43b4824ba710ff8f416eca" FOREIGN KEY ("forward_from_id") REFERENCES "user" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_8c442d060437d5621e14e749592" FOREIGN KEY ("forward_from_chat_id") REFERENCES "chats" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT "FK_0d4a0a3f31c0c82d8ca936d8752" FOREIGN KEY ("forward_from_message_id", "forward_from_message_chat") REFERENCES "messages" ("id", "chat_id") ON DELETE NO ACTION ON UPDATE NO ACTION, PRIMARY KEY ("id", "chat_id"))`, undefined);
await queryRunner.query(`INSERT INTO "temporary_messages"("id", "unixtime", "last_edit", "edit_history", "album_id", "signature", "text", "payload", "entities", "caption", "caption_entities", "audio", "document", "animation", "game", "photo", "sticker", "voice", "video_note", "video", "contact", "location", "venue", "new_group_title", "new_group_photo", "group_photo_deleted", "group_created", "supergroup_created", "channel_created", "forward_signature", "forward_date", "media_group_id", "author_signature", "invoice", "successful_payment", "connected_website", "passport_data", "created_at", "updated_at", "deleted_at", "sender_id", "reply_to_message_id", "chat_id", "user_joined_id", "user_left_id", "migrate_to_chat_id", "migrate_from_chat_id", "pinned_message_id", "pinned_message_chat", "forward_from_id", "forward_from_chat_id", "forward_from_message_id", "forward_from_message_chat") SELECT "id", "unixtime", "last_edit", "edit_history", "album_id", "signature", "text", "payload", "entities", "caption", "caption_entities", "audio", "document", "animation", "game", "photo", "sticker", "voice", "video_note", "video", "contact", "location", "venue", "new_group_title", "new_group_photo", "group_photo_deleted", "group_created", "supergroup_created", "channel_created", "forward_signature", "forward_date", "media_group_id", "author_signature", "invoice", "successful_payment", "connected_website", "passport_data", "created_at", "updated_at", "deleted_at", "sender_id", "reply_to_message_id", "chat_id", "user_joined_id", "user_left_id", "migrate_to_chat_id", "migrate_from_chat_id", "pinned_message_id", "pinned_message_chat", "forward_from_id", "forward_from_chat_id", "forward_from_message_id", "forward_from_message_chat" FROM "messages"`, undefined);
await queryRunner.query(`DROP TABLE "messages"`, undefined);
await queryRunner.query(`ALTER TABLE "temporary_messages" RENAME TO "messages"`, undefined);
// down(queryRunner: QueryRunner)
await queryRunner.query(`ALTER TABLE "messages" RENAME TO "temporary_messages"`, undefined);
await queryRunner.query(`CREATE TABLE "messages" ("id" bigint NOT NULL, "unixtime" bigint NOT NULL, "last_edit" datetime, "edit_history" text, "album_id" varchar, "signature" varchar, "text" varchar, "payload" varchar, "entities" text, "caption" varchar, "caption_entities" text, "audio" text, "document" text, "animation" text, "game" text, "photo" text, "sticker" text, "voice" text, "video_note" text, "video" text, "contact" text, "location" text, "venue" text, "new_group_title" varchar, "new_group_photo" text, "group_photo_deleted" boolean, "group_created" boolean, "supergroup_created" boolean, "channel_created" boolean, "forward_signature" varchar, "forward_date" datetime, "media_group_id" varchar, "author_signature" varchar, "invoice" text, "successful_payment" text, "connected_website" varchar, "passport_data" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL, "deleted_at" datetime, "sender_id" bigint, "reply_to_message_id" bigint, "chat_id" bigint NOT NULL, "user_joined_id" bigint, "user_left_id" bigint, "migrate_to_chat_id" bigint, "migrate_from_chat_id" bigint, "pinned_message_id" bigint, "pinned_message_chat" bigint, "forward_from_id" bigint, "forward_from_chat_id" bigint, "forward_from_message_id" bigint, "forward_from_message_chat" bigint, PRIMARY KEY ("id", "chat_id"))`, undefined);
await queryRunner.query(`INSERT INTO "messages"("id", "unixtime", "last_edit", "edit_history", "album_id", "signature", "text", "payload", "entities", "caption", "caption_entities", "audio", "document", "animation", "game", "photo", "sticker", "voice", "video_note", "video", "contact", "location", "venue", "new_group_title", "new_group_photo", "group_photo_deleted", "group_created", "supergroup_created", "channel_created", "forward_signature", "forward_date", "media_group_id", "author_signature", "invoice", "successful_payment", "connected_website", "passport_data", "created_at", "updated_at", "deleted_at", "sender_id", "reply_to_message_id", "chat_id", "user_joined_id", "user_left_id", "migrate_to_chat_id", "migrate_from_chat_id", "pinned_message_id", "pinned_message_chat", "forward_from_id", "forward_from_chat_id", "forward_from_message_id", "forward_from_message_chat") SELECT "id", "unixtime", "last_edit", "edit_history", "album_id", "signature", "text", "payload", "entities", "caption", "caption_entities", "audio", "document", "animation", "game", "photo", "sticker", "voice", "video_note", "video", "contact", "location", "venue", "new_group_title", "new_group_photo", "group_photo_deleted", "group_created", "supergroup_created", "channel_created", "forward_signature", "forward_date", "media_group_id", "author_signature", "invoice", "successful_payment", "connected_website", "passport_data", "created_at", "updated_at", "deleted_at", "sender_id", "reply_to_message_id", "chat_id", "user_joined_id", "user_left_id", "migrate_to_chat_id", "migrate_from_chat_id", "pinned_message_id", "pinned_message_chat", "forward_from_id", "forward_from_chat_id", "forward_from_message_id", "forward_from_message_chat" FROM "temporary_messages"`, undefined);
await queryRunner.query(`DROP TABLE "temporary_messages"`, undefined);