How to use webhook.send method in qawolf

Best JavaScript code snippet using qawolf

webhooks.test.js

Source:webhooks.test.js Github

copy

Full Screen

1import got from 'got';2import moment from 'moment';3import {4 WebhookSender,5 taskScoredWebhook,6 groupChatReceivedWebhook,7 taskActivityWebhook,8 questActivityWebhook,9 userActivityWebhook,10} from '../../../../website/server/libs/webhook';11import {12 model as User,13} from '../../../../website/server/models/user';14import {15 generateUser,16 defer,17 sleep,18} from '../../../helpers/api-unit.helper';19import logger from '../../../../website/server/libs/logger';20describe('webhooks', () => {21 let webhooks; let22 user;23 beforeEach(() => {24 sandbox.stub(got, 'post').returns(defer().promise);25 webhooks = [{26 id: 'taskActivity',27 url: 'http://task-scored.com',28 enabled: true,29 type: 'taskActivity',30 options: {31 created: true,32 updated: true,33 deleted: true,34 scored: true,35 checklistScored: true,36 },37 }, {38 id: 'questActivity',39 url: 'http://quest-activity.com',40 enabled: true,41 type: 'questActivity',42 options: {43 questStarted: true,44 questFinised: true,45 questInvited: true,46 },47 }, {48 id: 'userActivity',49 url: 'http://user-activity.com',50 enabled: true,51 type: 'userActivity',52 options: {53 petHatched: true,54 mountRaised: true,55 leveledUp: true,56 },57 }, {58 id: 'groupChatReceived',59 url: 'http://group-chat-received.com',60 enabled: true,61 type: 'groupChatReceived',62 options: {63 groupId: 'group-id',64 },65 }];66 user = generateUser();67 user.webhooks = webhooks;68 });69 afterEach(() => {70 sandbox.restore();71 });72 describe('WebhookSender', () => {73 it('creates a new WebhookSender object', () => {74 const sendWebhook = new WebhookSender({75 type: 'custom',76 });77 expect(sendWebhook.type).to.equal('custom');78 expect(sendWebhook).to.respondTo('send');79 });80 it('provides default function for data transformation', () => {81 sandbox.spy(WebhookSender, 'defaultTransformData');82 const sendWebhook = new WebhookSender({83 type: 'custom',84 });85 const body = { foo: 'bar' };86 user.webhooks = [{87 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom',88 }];89 sendWebhook.send(user, body);90 expect(WebhookSender.defaultTransformData).to.be.calledOnce;91 expect(got.post).to.be.calledOnce;92 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {93 json: body,94 });95 });96 it('adds default data (user and webhookType) to the body', () => {97 const sendWebhook = new WebhookSender({98 type: 'custom',99 });100 sandbox.spy(sendWebhook, 'attachDefaultData');101 const body = { foo: 'bar' };102 user.webhooks = [{103 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom',104 }];105 sendWebhook.send(user, body);106 expect(sendWebhook.attachDefaultData).to.be.calledOnce;107 expect(got.post).to.be.calledOnce;108 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {109 json: body,110 });111 expect(body).to.eql({112 foo: 'bar',113 user: { _id: user._id },114 webhookType: 'custom',115 });116 });117 it('can pass in a data transformation function', () => {118 sandbox.spy(WebhookSender, 'defaultTransformData');119 const sendWebhook = new WebhookSender({120 type: 'custom',121 transformData (data) {122 const dataToSend = { baz: 'biz', ...data };123 return dataToSend;124 },125 });126 const body = { foo: 'bar' };127 user.webhooks = [{128 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom',129 }];130 sendWebhook.send(user, body);131 expect(WebhookSender.defaultTransformData).to.not.be.called;132 expect(got.post).to.be.calledOnce;133 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {134 json: {135 foo: 'bar',136 baz: 'biz',137 },138 });139 });140 it('provides a default filter function', () => {141 sandbox.spy(WebhookSender, 'defaultWebhookFilter');142 const sendWebhook = new WebhookSender({143 type: 'custom',144 });145 const body = { foo: 'bar' };146 user.webhooks = [{147 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom',148 }];149 sendWebhook.send(user, body);150 expect(WebhookSender.defaultWebhookFilter).to.be.calledOnce;151 });152 it('can pass in a webhook filter function', () => {153 sandbox.spy(WebhookSender, 'defaultWebhookFilter');154 const sendWebhook = new WebhookSender({155 type: 'custom',156 webhookFilter (hook) {157 return hook.url !== 'http://custom-url.com';158 },159 });160 const body = { foo: 'bar' };161 user.webhooks = [{162 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom',163 }];164 sendWebhook.send(user, body);165 expect(WebhookSender.defaultWebhookFilter).to.not.be.called;166 expect(got.post).to.not.be.called;167 });168 it('can pass in a webhook filter function that filters on data', () => {169 sandbox.spy(WebhookSender, 'defaultWebhookFilter');170 const sendWebhook = new WebhookSender({171 type: 'custom',172 webhookFilter (hook, data) {173 return hook.options.foo === data.foo;174 },175 });176 const body = { foo: 'bar' };177 user.webhooks = [178 {179 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom', options: { foo: 'bar' },180 },181 {182 id: 'other-custom-webhook', url: 'http://other-custom-url.com', enabled: true, type: 'custom', options: { foo: 'foo' },183 },184 ];185 sendWebhook.send(user, body);186 expect(got.post).to.be.calledOnce;187 expect(got.post).to.be.calledWithMatch('http://custom-url.com');188 });189 it('ignores disabled webhooks', () => {190 const sendWebhook = new WebhookSender({191 type: 'custom',192 });193 const body = { foo: 'bar' };194 user.webhooks = [{195 id: 'custom-webhook', url: 'http://custom-url.com', enabled: false, type: 'custom',196 }];197 sendWebhook.send(user, body);198 expect(got.post).to.not.be.called;199 });200 it('ignores webhooks with invalid urls', () => {201 const sendWebhook = new WebhookSender({202 type: 'custom',203 });204 const body = { foo: 'bar' };205 user.webhooks = [{206 id: 'custom-webhook', url: 'httxp://custom-url!!!', enabled: true, type: 'custom',207 }];208 sendWebhook.send(user, body);209 expect(got.post).to.not.be.called;210 });211 it('ignores webhooks of other types', () => {212 const sendWebhook = new WebhookSender({213 type: 'custom',214 });215 const body = { foo: 'bar' };216 user.webhooks = [217 {218 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom',219 },220 {221 id: 'other-webhook', url: 'http://other-url.com', enabled: true, type: 'other',222 },223 ];224 sendWebhook.send(user, body);225 expect(got.post).to.be.calledOnce;226 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {227 json: body,228 });229 });230 it('sends every type of activity to global webhooks', () => {231 const sendWebhook = new WebhookSender({232 type: 'custom',233 });234 const body = { foo: 'bar' };235 user.webhooks = [236 {237 id: 'global-webhook', url: 'http://custom-url.com', enabled: true, type: 'globalActivity',238 },239 ];240 sendWebhook.send(user, body);241 expect(got.post).to.be.calledOnce;242 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {243 json: body,244 });245 });246 it('sends multiple webhooks of the same type', () => {247 const sendWebhook = new WebhookSender({248 type: 'custom',249 });250 const body = { foo: 'bar' };251 user.webhooks = [252 {253 id: 'custom-webhook', url: 'http://custom-url.com', enabled: true, type: 'custom',254 },255 {256 id: 'other-custom-webhook', url: 'http://other-url.com', enabled: true, type: 'custom',257 },258 ];259 sendWebhook.send(user, body);260 expect(got.post).to.be.calledTwice;261 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {262 json: body,263 });264 expect(got.post).to.be.calledWithMatch('http://other-url.com', {265 json: body,266 });267 });268 describe('failures', () => {269 let sendWebhook;270 beforeEach(async () => {271 sandbox.restore();272 sandbox.stub(got, 'post').returns(Promise.reject());273 sendWebhook = new WebhookSender({ type: 'taskActivity' });274 user.webhooks = [{275 url: 'http://custom-url.com', enabled: true, type: 'taskActivity',276 }];277 await user.save();278 expect(user.webhooks[0].failures).to.equal(0);279 expect(user.webhooks[0].lastFailureAt).to.equal(undefined);280 });281 it('does not increase failures counter if request is successfull', async () => {282 sandbox.restore();283 sandbox.stub(got, 'post').returns(Promise.resolve());284 const body = {};285 sendWebhook.send(user, body);286 expect(got.post).to.be.calledOnce;287 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {288 json: body,289 });290 await sleep(0.1);291 user = await User.findById(user._id).exec();292 expect(user.webhooks[0].failures).to.equal(0);293 expect(user.webhooks[0].lastFailureAt).to.equal(undefined);294 });295 it('records failures', async () => {296 sinon.stub(logger, 'error');297 const body = {};298 sendWebhook.send(user, body);299 expect(got.post).to.be.calledOnce;300 expect(got.post).to.be.calledWithMatch('http://custom-url.com', {301 json: body,302 });303 await sleep(0.1);304 user = await User.findById(user._id).exec();305 expect(user.webhooks[0].failures).to.equal(1);306 expect((Date.now() - user.webhooks[0].lastFailureAt.getTime()) < 10000).to.be.true;307 expect(logger.error).to.be.calledOnce;308 logger.error.restore();309 });310 it('disables a webhook after 10 failures', async () => {311 const times = 10;312 for (let i = 0; i < times; i += 1) {313 sendWebhook.send(user, {});314 await sleep(0.1); // eslint-disable-line no-await-in-loop315 user = await User.findById(user._id).exec(); // eslint-disable-line no-await-in-loop316 }317 expect(got.post).to.be.callCount(10);318 expect(got.post).to.be.calledWithMatch('http://custom-url.com');319 await sleep(0.1);320 user = await User.findById(user._id).exec();321 expect(user.webhooks[0].enabled).to.equal(false);322 expect(user.webhooks[0].failures).to.equal(0);323 });324 it('resets failures after a month ', async () => {325 const oneMonthAgo = moment().subtract(1, 'months').subtract(1, 'days').toDate();326 user.webhooks[0].lastFailureAt = oneMonthAgo;327 user.webhooks[0].failures = 9;328 await user.save();329 sendWebhook.send(user, []);330 expect(got.post).to.be.calledOnce;331 expect(got.post).to.be.calledWithMatch('http://custom-url.com');332 await sleep(0.1);333 user = await User.findById(user._id).exec();334 expect(user.webhooks[0].failures).to.equal(1);335 // Check that the stored date is whitin 10s from now336 expect((Date.now() - user.webhooks[0].lastFailureAt.getTime()) < 10000).to.be.true;337 });338 });339 });340 describe('taskScoredWebhook', () => {341 let data;342 beforeEach(() => {343 data = {344 user: {345 _tmp: { foo: 'bar' },346 stats: {347 lvl: 5,348 int: 10,349 str: 5,350 exp: 423,351 toJSON () {352 return this;353 },354 },355 },356 task: {357 text: 'text',358 },359 direction: 'up',360 delta: 176,361 };362 const mockStats = {363 maxHealth: 50,364 maxMP: 103,365 toNextLevel: 40,366 ...data.user.stats,367 };368 delete mockStats.toJSON;369 sandbox.stub(User, 'addComputedStatsToJSONObj').returns(mockStats);370 });371 it('sends task and stats data', () => {372 taskScoredWebhook.send(user, data);373 expect(got.post).to.be.calledOnce;374 expect(got.post).to.be.calledWithMatch(webhooks[0].url, {375 json: {376 type: 'scored',377 webhookType: 'taskActivity',378 user: {379 _id: user._id,380 _tmp: { foo: 'bar' },381 stats: {382 lvl: 5,383 int: 10,384 str: 5,385 exp: 423,386 toNextLevel: 40,387 maxHealth: 50,388 maxMP: 103,389 },390 },391 task: {392 text: 'text',393 },394 direction: 'up',395 delta: 176,396 },397 });398 });399 it('sends task and stats data to globalActivity webhookd', () => {400 user.webhooks = [{401 id: 'globalActivity',402 url: 'http://global-activity.com',403 enabled: true,404 type: 'globalActivity',405 }];406 taskScoredWebhook.send(user, data);407 expect(got.post).to.be.calledOnce;408 expect(got.post).to.be.calledWithMatch('http://global-activity.com', {409 json: {410 type: 'scored',411 webhookType: 'taskActivity',412 user: {413 _id: user._id,414 _tmp: { foo: 'bar' },415 stats: {416 lvl: 5,417 int: 10,418 str: 5,419 exp: 423,420 toNextLevel: 40,421 maxHealth: 50,422 maxMP: 103,423 },424 },425 task: {426 text: 'text',427 },428 direction: 'up',429 delta: 176,430 },431 });432 });433 it('does not send task scored data if scored option is not true', () => {434 webhooks[0].options.scored = false;435 taskScoredWebhook.send(user, data);436 expect(got.post).to.not.be.called;437 });438 });439 describe('taskActivityWebhook', () => {440 let data;441 beforeEach(() => {442 data = {443 task: {444 text: 'text',445 },446 };447 });448 ['created', 'updated', 'deleted'].forEach(type => {449 it(`sends ${type} tasks`, () => {450 data.type = type;451 taskActivityWebhook.send(user, data);452 expect(got.post).to.be.calledOnce;453 expect(got.post).to.be.calledWithMatch(webhooks[0].url, {454 json: {455 type,456 webhookType: 'taskActivity',457 user: {458 _id: user._id,459 },460 task: data.task,461 },462 });463 });464 it(`does not send task ${type} data if ${type} option is not true`, () => {465 data.type = type;466 webhooks[0].options[type] = false;467 taskActivityWebhook.send(user, data);468 expect(got.post).to.not.be.called;469 });470 });471 describe('checklistScored', () => {472 beforeEach(() => {473 data = {474 task: {475 text: 'text',476 },477 item: {478 text: 'item-text',479 },480 };481 });482 it('sends \'checklistScored\' tasks', () => {483 data.type = 'checklistScored';484 taskActivityWebhook.send(user, data);485 expect(got.post).to.be.calledOnce;486 expect(got.post).to.be.calledWithMatch(webhooks[0].url, {487 json: {488 webhookType: 'taskActivity',489 user: {490 _id: user._id,491 },492 type: data.type,493 task: data.task,494 item: data.item,495 },496 });497 });498 it('does not send task \'checklistScored\' data if \'checklistScored\' option is not true', () => {499 data.type = 'checklistScored';500 webhooks[0].options.checklistScored = false;501 taskActivityWebhook.send(user, data);502 expect(got.post).to.not.be.called;503 });504 });505 });506 describe('userActivityWebhook', () => {507 let data;508 beforeEach(() => {509 data = {510 something: true,511 };512 });513 ['petHatched', 'mountRaised', 'leveledUp'].forEach(type => {514 it(`sends ${type} webhooks`, () => {515 data.type = type;516 userActivityWebhook.send(user, data);517 expect(got.post).to.be.calledOnce;518 expect(got.post).to.be.calledWithMatch(webhooks[2].url, {519 json: {520 type,521 webhookType: 'userActivity',522 user: {523 _id: user._id,524 },525 something: true,526 },527 });528 });529 it(`does not send webhook ${type} data if ${type} option is not true`, () => {530 data.type = type;531 webhooks[2].options[type] = false;532 userActivityWebhook.send(user, data);533 expect(got.post).to.not.be.called;534 });535 });536 });537 describe('questActivityWebhook', () => {538 let data;539 beforeEach(() => {540 data = {541 group: {542 id: 'group-id',543 name: 'some group',544 otherData: 'foo',545 },546 quest: {547 key: 'some-key',548 },549 };550 });551 ['questStarted', 'questFinised', 'questInvited'].forEach(type => {552 it(`sends ${type} webhooks`, () => {553 data.type = type;554 questActivityWebhook.send(user, data);555 expect(got.post).to.be.calledOnce;556 expect(got.post).to.be.calledWithMatch(webhooks[1].url, {557 json: {558 type,559 webhookType: 'questActivity',560 user: {561 _id: user._id,562 },563 group: {564 id: 'group-id',565 name: 'some group',566 },567 quest: {568 key: 'some-key',569 },570 },571 });572 });573 it(`does not send webhook ${type} data if ${type} option is not true`, () => {574 data.type = type;575 webhooks[1].options[type] = false;576 userActivityWebhook.send(user, data);577 expect(got.post).to.not.be.called;578 });579 });580 });581 describe('groupChatReceivedWebhook', () => {582 it('sends chat data', () => {583 const data = {584 group: {585 id: 'group-id',586 name: 'some group',587 otherData: 'foo',588 },589 chat: {590 id: 'some-id',591 text: 'message',592 },593 };594 groupChatReceivedWebhook.send(user, data);595 expect(got.post).to.be.calledOnce;596 expect(got.post).to.be.calledWithMatch(webhooks[webhooks.length - 1].url, {597 json: {598 webhookType: 'groupChatReceived',599 user: {600 _id: user._id,601 },602 group: {603 id: 'group-id',604 name: 'some group',605 },606 chat: {607 id: 'some-id',608 text: 'message',609 },610 },611 });612 });613 it('does not send chat data for group if not selected', () => {614 const data = {615 group: {616 id: 'not-group-id',617 name: 'some group',618 otherData: 'foo',619 },620 chat: {621 id: 'some-id',622 text: 'message',623 },624 };625 groupChatReceivedWebhook.send(user, data);626 expect(got.post).to.not.be.called;627 });628 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...17 .setDescription(`❌ Message deleted in ${message.channel}`)18 .addField("**Content**", message.content)19 .setTimestamp()20 .setFooter({text: "Message ID: " + message.id});21 webhook.send({ embeds: [embed] }).catch(console.error);22 }23});24client.on('messageUpdate', (oldMessage, newMessage) => {25 if (oldMessage.content != newMessage.content) {26 let embed = new Discord.MessageEmbed()27 .setAuthor({name: oldMessage.author.username + "#" + oldMessage.author.discriminator,28 iconURL: oldMessage.author.avatarURL()})29 .setDescription(`📖 Message edited in ${oldMessage.channel}`)30 .addField("**Before**", oldMessage.content)31 .addField("**After**", newMessage.content)32 .setTimestamp()33 .setFooter({text: "Message ID: " + newMessage.id});34 webhook.send({ embeds: [embed] }).catch(console.error);35 }36});37client.on('channelCreate', (channel) => {38 let embed = new Discord.MessageEmbed()39 .setDescription(`✅ Channel created ${channel}`)40 .addField("**Name**", channel.name, true)41 .addField("**ID**", channel.id, true)42 .setTimestamp();43 webhook.send({ embeds: [embed] }).catch(console.error);44});45client.on('channelDelete', (channel) => {46 let embed = new Discord.MessageEmbed()47 .setDescription(`❌ Channel **${channel.name}** deleted `)48 .setTimestamp();49 webhook.send({ embeds: [embed] }).catch(console.error);50});51client.on("roleDelete", function (role) {52 let embed = new Discord.MessageEmbed()53 .setDescription(`❌ Role deleted`)54 .addField("**Name**", role.name, true)55 .addField("**ID**", role.id, true)56 .setTimestamp();57 webhook.send({ embeds: [embed] }).catch(console.error);58});59client.on('guildMemberAdd', (member) => {60 let embed = new Discord.MessageEmbed()61 .setAuthor({name: member.user.username + "#" + member.user.discriminator,62 iconURL: member.user.displayAvatarURL()})63 .setDescription(`✅ **User joined** ${member.user}`)64 .addField("**Name**", member.user.username, true)65 .addField("**ID**", member.user.id, true)66 .setTimestamp();67 webhook.send({ embeds: [embed] }).catch(console.error);68});69client.on('guildMemberRemove', (member) => {70 let embed = new Discord.MessageEmbed()71 .setAuthor({name: member.user.username + "#" + member.user.discriminator,72 iconURL: member.user.displayAvatarURL()})73 .setDescription(`❌ **User leaved** ${member.user}`)74 .addField("**Name**", member.user.username, true)75 .addField("**ID**", member.user.id, true)76 .setTimestamp();77 webhook.send({ embeds: [embed] }).catch(console.error);78});79client.on('guildBanAdd', (ban) => {80 let embed = new Discord.MessageEmbed()81 .setDescription(`❌ Baned user ${ban.user}`)82 .setTimestamp()83 .setFooter({text: "User ID: " + ban.user.id});84 webhook.send({ embeds: [embed] }).catch(console.error);85});86client.on('guildBanRemove', (ban) => {87 let embed = new Discord.MessageEmbed()88 .setDescription(`✅ Unbaned user ${ban.user}`)89 .setTimestamp()90 .setFooter({text: "User ID: " + ban.user.id});91 webhook.send({ embeds: [embed] }).catch(console.error);92});93client.on("roleCreate", function (role) {94 let embed = new Discord.MessageEmbed()95 .setDescription(`✅ Role created`)96 .addField("**Name**", role.name, true)97 .setTimestamp()98 .setFooter({text: "Role ID: " + role.id});99 webhook.send({ embeds: [embed] }).catch(console.error);100});101client.on("roleUpdate", function (oldRole, newRole) {102 if (oldRole.name != newRole.name) {103 let embed = new Discord.MessageEmbed()104 .setDescription(`♻️ Role name updated`)105 .addField("**Old name**", oldRole.name, true)106 .addField("**New name**", newRole.name, true)107 .setTimestamp()108 .setFooter({text: "Role ID: " + newRole.id});109 webhook.send({ embeds: [embed] }).catch(console.error);110 };111});112client.on("roleDelete", function (role) {113 let embed = new Discord.MessageEmbed()114 .setDescription(`❌ Role deleted`)115 .addField("**Name**", role.name, true)116 .setTimestamp()117 .setFooter({text: "Role ID: " + role.id});118 webhook.send({ embeds: [embed] }).catch(console.error);119});120client.on("guildMemberUpdate", (oldMember, newMember) => {121 let oldnick = oldMember.user.username;122 let newnick = newMember.user.username;123 if (oldMember.nickname) {124 oldnick = oldMember.nickname};125 if (newMember.nickname) {126 newnick = newMember.nickname};127 if (oldnick != newnick) {128 let embed = new Discord.MessageEmbed()129 .setAuthor({name: newMember.user.username + "#" + newMember.user.discriminator,130 iconURL: newMember.user.displayAvatarURL()})131 .setDescription(`♻️ Username updated`)132 .addField("**Old name**", oldnick, true)133 .addField("**New name**", newnick, true)134 .setTimestamp()135 .setFooter({text: "User ID: " + newMember.user.id});136 webhook.send({ embeds: [embed] }).catch(console.error);137 };138});139client.on('voiceStateUpdate', (oldState, newState) => {140 let oldChannelName = (oldState.channelId != null && typeof oldState.channelId != undefined) ? client.channels.cache.get(oldState.channelId).name : null;141 let newChannelName = (newState.channelId != null && typeof newState.channelId != undefined) ? client.channels.cache.get(newState.channelId).name : null;142 let oldChannel = (oldState.channelId != null && typeof oldState.channelId != undefined) ? client.channels.cache.get(oldState.channelId) : null;143 let newChannel = (newState.channelId != null && typeof newState.channelId != undefined) ? client.channels.cache.get(newState.channelId) : null;144 if (oldChannelName === null) {145 let embed = new Discord.MessageEmbed()146 .setAuthor({name: oldState.member.user.username + "#" + oldState.member.user.discriminator,147 iconURL: oldState.member.user.displayAvatarURL()})148 .setDescription(`${oldState.member.user} connected to voice and joined ${newChannel}`)149 .setTimestamp();150 webhook.send({ embeds: [embed] }).catch(console.error);151 }152 else if (newChannelName === null) {153 let embed = new Discord.MessageEmbed()154 .setAuthor({name: oldState.member.user.username + "#" + oldState.member.user.discriminator,155 iconURL: oldState.member.user.displayAvatarURL()})156 .setDescription(`${oldState.member.user} disconnected`)157 .setTimestamp();158 webhook.send({ embeds: [embed] }).catch(console.error);159 }160 else {161 if (newState.channelId != oldState.channelId) {162 let embed = new Discord.MessageEmbed()163 .setAuthor({name: oldState.member.user.username + "#" + oldState.member.user.discriminator,164 iconURL: oldState.member.user.displayAvatarURL()})165 .setDescription(`❌ ${oldState.member.user} moved to channel ${newChannel}`)166 .setTimestamp();167 webhook.send({ embeds: [embed] }).catch(console.error);168 }169 if (oldState.serverMute != newState.serverMute) {170 if (newState.serverMute == true) {171 let embed = new Discord.MessageEmbed()172 .setAuthor({name: oldState.member.user.username + "#" + oldState.member.user.discriminator,173 iconURL: oldState.member.user.displayAvatarURL()})174 .setDescription(`❌ ${oldState.member.user} muted in channel ${newChannel}`)175 .setTimestamp();176 webhook.send({ embeds: [embed] }).catch(console.error);177 }178 if (newState.serverMute == false) {179 let embed = new Discord.MessageEmbed()180 .setAuthor({name: oldState.member.user.username + "#" + oldState.member.user.discriminator,181 iconURL: oldState.member.user.displayAvatarURL()})182 .setDescription(`✅ ${oldState.member.user} unmuted in channel ${newChannel}`)183 .setTimestamp();184 webhook.send({ embeds: [embed] }).catch(console.error);185 }186 }187 if (oldState.serverDeaf != newState.serverDeaf) {188 if (newState.serverDeaf == true) {189 let embed = new Discord.MessageEmbed()190 .setAuthor({name: oldState.member.user.username + "#" + oldState.member.user.discriminator,191 iconURL: oldState.member.user.displayAvatarURL()})192 .setDescription(`❌ ${oldState.member.user} deafed in channel ${newChannel}`)193 .setTimestamp();194 webhook.send({ embeds: [embed] }).catch(console.error);195 }196 if (newState.serverDeaf == false) {197 let embed = new Discord.MessageEmbed()198 .setAuthor({name: oldState.member.user.username + "#" + oldState.member.user.discriminator,199 iconURL: oldState.member.user.displayAvatarURL()})200 .setDescription(`✅ ${oldState.member.user} undeafed in channel ${newChannel}`)201 .setTimestamp();202 webhook.send({ embeds: [embed] }).catch(console.error);203 }204 }205 }206});...

Full Screen

Full Screen

emoji.js

Source:emoji.js Github

copy

Full Screen

...20 const webhook = await message.channel.createWebhook(user.username, {21 avatar: user.displayAvatarURL(),22 channel: (message.channel/*was channelTarget*/)23 })24 await webhook.send("<:pepeOkie:802130802498207785> " + args.join(' ')||("")).then(() => {25 webhook.delete()})26 27 } else if (command === 'pepehappy') {28 const user = message.author29 const webhook = await message.channel.createWebhook(user.username, {30 avatar: user.displayAvatarURL(),31 channel: (message.channel/*was channelTarget*/)32 })33 await webhook.send("<:pepeHappy:802467102724194324> " + args.join(' ')||("")).then(() => {34 webhook.delete()})35 36 37 } else if (command === 'pepesalute'){38 const user = message.author39 const webhook = await message.channel.createWebhook(user.username, {40 avatar: user.displayAvatarURL(),41 channel: (message.channel/*was channelTarget*/)42 })43 await webhook.send("<:PepeSoldierSalute:802467139562504202> " + args.join(' ')||("")).then(() => {44 webhook.delete()})45 46 47 } else if (command === 'pepeping'){48 const user = message.author49 const webhook = await message.channel.createWebhook(user.username, {50 avatar: user.displayAvatarURL(),51 channel: (message.channel/*was channelTarget*/)52 })53 await webhook.send("<:PeepoPing:804776979777323098> " + args.join(' ')||("")).then(() => {54 webhook.delete()})55 56 57 } else if (command === 'pepe'){58 const user = message.author59 const webhook = await message.channel.createWebhook(user.username, {60 avatar: user.displayAvatarURL(),61 channel: (message.channel/*was channelTarget*/)62 })63 await webhook.send("<:monkaS:804776979092996136> " + args.join(' ')||("")).then(() => {64 webhook.delete()})65 66 67 } else if (command === 'pepeban'){68 const user = message.author69 const webhook = await message.channel.createWebhook(user.username, {70 avatar: user.displayAvatarURL(),71 channel: (message.channel/*was channelTarget*/)72 })73 await webhook.send("<:FeelsBanMan:804776978379964416> " + args.join(' ')||("")).then(() => {74 webhook.delete()})75 76 } else if (command === 'pepecry'){77 const user = message.author78 const webhook = await message.channel.createWebhook(user.username, {79 avatar: user.displayAvatarURL(),80 channel: (message.channel/*was channelTarget*/)81 })82 await webhook.send("<:PepeHands:791190431298879538> " + args.join(' ')||("")).then(() => {83 webhook.delete()})84 85 } else if (command === 'pepesword'){86 const user = message.author87 const webhook = await message.channel.createWebhook(user.username, {88 avatar: user.displayAvatarURL(),89 channel: (message.channel/*was channelTarget*/)90 })91 await webhook.send("<a:3048_Pepe_Sword:800631693719371797> " + args.join(' ')||("")).then(() => {92 webhook.delete()})93 94 } else if (command === 'pepesweat'){95 const user = message.author96 const webhook = await message.channel.createWebhook(user.username, {97 avatar: user.displayAvatarURL(),98 channel: (message.channel/*was channelTarget*/)99 })100 await webhook.send("<:pepeSweat:802114117724143616> " + args.join(' ')||("")).then(() => {101 webhook.delete()})102 103 } else if (command === 'pepefestive'){104 const user = message.author105 const webhook = await message.channel.createWebhook(user.username, {106 avatar: user.displayAvatarURL(),107 channel: (message.channel/*was channelTarget*/)108 })109 await webhook.send("<:festivepepe:804776979786104882> " + args.join(' ')||("")).then(() => {110 webhook.delete()})111 112 } else if (command === 'pepeyikes'){113 const user = message.author114 const webhook = await message.channel.createWebhook(user.username, {115 avatar: user.displayAvatarURL(),116 channel: (message.channel/*was channelTarget*/)117 })118 await webhook.send("<:PepeYikes:804776979320143952> " + args.join(' ')||("")).then(() => {119 webhook.delete()})120 121 } else if (command === 'pepekms'){ 122 const user = message.author123 const webhook = await message.channel.createWebhook(user.username, {124 avatar: user.displayAvatarURL(),125 channel: (message.channel/*was channelTarget*/)126 })127 await webhook.send("<:PepeKMS:804776980397686814> " + args.join(' ')||("")).then(() => {128 webhook.delete()})129 130 131 } else if (command === 'pepechef'){132 const user = message.author133 const webhook = await message.channel.createWebhook(user.username, {134 avatar: user.displayAvatarURL(), 135 channel: (message.channel/*was channelTarget*/)136 })137 await webhook.send("<:8061_pepe_chef:800258706695782410> " + args.join(' ')||("")).then(() => {138 webhook.delete()})139 140 }else if (command === 'pepepack'){141 let embed = new Discord.MessageEmbed()142.setTitle('Pepepack<:monkaS:804776979092996136>')143.setDescription(`Type ${prefix}emojiname (ur text) to add the emoji infront of ur text`)144.addFields(145 {name: 'pepeok', value: `<:pepeOkie:802130802498207785>`, inline: true},146 {name: 'pepehappy', value: `<:pepeHappy:802467102724194324>`, inline: true},147 148 {name: 'pepesalute', value: `<:PepeSoldierSalute:802467139562504202>`, inline: true},149 {name: 'pepeping', value: `<:PeepoPing:804776979777323098>`, inline: true},150 {name: 'pepe', value: `<:monkaS:804776979092996136>`, inline: true},151 {name: 'pepeban', value: `<:FeelsBanMan:804776978379964416>`, inline: true}, ...

Full Screen

Full Screen

notificationFormatter.spec.ts

Source:notificationFormatter.spec.ts Github

copy

Full Screen

...8 },9 }10describe('notificationFormatter', () => {11 it('automaticTransferRegistrationCreated', async () => {12 await webhook.send(13 notificationFormatter.automaticTransferRegistrationCreated({14 type: 'automaticTransferRegistrationCreated',15 name: 'オフィス賃料',16 transferDate: '月末日',17 }),18 )19 })20 it('automaticTransferRegistrationDeleted', async () => {21 await webhook.send(22 notificationFormatter.automaticTransferRegistrationDeleted({23 type: 'automaticTransferRegistrationDeleted',24 name: 'オフィス賃料',25 transferDate: '月末日',26 }),27 )28 })29 it('automaticTransferRegistrationUpdated', async () => {30 await webhook.send(31 notificationFormatter.automaticTransferRegistrationUpdated({32 type: 'automaticTransferRegistrationUpdated',33 name: 'オフィス賃料',34 transferDate: '月末日',35 }),36 )37 })38 it('bulkTransferFeeCharged', async () => {39 await webhook.send(40 notificationFormatter.bulkTransferFeeCharged({41 type: 'bulkTransferFeeCharged',42 chargeDate: '2020-06-25',43 }),44 )45 })46 it('bulkTransferUpcoming', async () => {47 await webhook.send(48 notificationFormatter.bulkTransferUpcoming({49 type: 'bulkTransferUpcoming',50 number: '200619-001',51 transferDate: '2020-06-25',52 }),53 )54 })55 it('payeasyPaid', async () => {56 await webhook.send(57 notificationFormatter.payeasyPaid({58 type: 'payeasyPaid',59 receiptNumber: '2020071002866599',60 paidOn: '2020-07-10T08:52:12+09:00',61 payee: '地方税共同機構',62 paymentNumber: '18020622256625',63 name: 'クラフトマンソフトウエア',64 detail: '住民特徴02年06月',65 amount: 132_600,66 fee: 0,67 }),68 )69 })70 it('timeDepositAutomaticallyRenewed', async () => {71 await webhook.send(72 notificationFormatter.timeDepositAutomaticallyRenewed({73 type: 'timeDepositAutomaticallyRenewed',74 number: '0143',75 renewalDate: '2020-07-01',76 }),77 )78 })79 it('timeDepositCreated', async () => {80 await webhook.send(81 notificationFormatter.timeDepositCreated({82 type: 'timeDepositCreated',83 number: '0143',84 }),85 )86 })87 it('timeDepositMatured', async () => {88 await webhook.send(89 notificationFormatter.timeDepositMatured({90 type: 'timeDepositMatured',91 number: '0143',92 }),93 )94 })95 it('timeDepositWillMature', async () => {96 await webhook.send(97 notificationFormatter.timeDepositWillMature({98 type: 'timeDepositWillMature',99 number: '0143',100 maturityDate: '2020-07-01',101 }),102 )103 })104 describe('transferDeposited', () => {105 test('unit', () => {106 const message = notificationFormatter.transferDeposited({107 type: 'transferDeposited',108 depositedOn: '2000-01-02T03:04:05+09:00',109 })110 const text = message.attachments?.[0]?.text111 expect(text).toContain('入金がありました。')112 expect(text).toContain('*入金日時* 2000年1月2日(日) 03:04')113 })114 test('integration', async () => {115 await webhook.send(116 notificationFormatter.transferDeposited({117 type: 'transferDeposited',118 depositedOn: '2000-01-02T03:04:05+09:00',119 }),120 )121 })122 })123 it('transferDestinationRegistered', async () => {124 await webhook.send(125 notificationFormatter.transferDestinationRegistered({126 type: 'transferDestinationRegistered',127 recipient: 'カ)クラフトマンソフトウエ..',128 bank: '三菱UFJ銀行',129 registeredOn: '2000-01-02T03:04:05+09:00',130 }),131 )132 })133 it('transferWithdrawalLimitChanged', async () => {134 await webhook.send(135 notificationFormatter.transferWithdrawalLimitChanged({136 type: 'transferWithdrawalLimitChanged',137 changedOn: '2000-01-02T03:04:05+09:00',138 }),139 )140 })141 it('transferWithdrawalScheduled', async () => {142 await webhook.send(143 notificationFormatter.transferWithdrawalScheduled({144 type: 'transferWithdrawalScheduled',145 number: '202007080077840',146 amount: 134383,147 recipient: 'カ)クラフトマンソフトウエ..',148 scheduledDate: '2020-01-02',149 }),150 )151 })152 it('transferWithdrawn', async () => {153 await webhook.send(154 notificationFormatter.transferWithdrawn({155 type: 'transferWithdrawn',156 withdrawnOn: '2000-01-02T03:04:05+09:00',157 number: '202007080077840',158 amount: 134383,159 recipient: 'カ)クラフトマンソフトウエ..',160 }),161 )162 })163 it('visaFrozen', async () => {164 await webhook.send(165 notificationFormatter.visaFrozen({166 type: 'visaFrozen',167 frozenOn: '2000-01-02T03:04:05+09:00',168 }),169 )170 })171 it('visaLimitChanged', async () => {172 await webhook.send(173 notificationFormatter.visaLimitChanged({174 type: 'visaLimitChanged',175 changedOn: '2000-01-02T03:04:05+09:00',176 newLimit: 1000000,177 }),178 )179 })180 it('visaRefunded', async () => {181 await webhook.send(182 notificationFormatter.visaRefunded({183 type: 'visaRefunded',184 refundedOn: '2000-01-02T03:04:05+09:00',185 shop: 'AMAZON CO JP',186 amount: 100000,187 number: '1A001001',188 }),189 )190 })191 describe('visaWithdrawn', () => {192 test('unit', () => {193 const message = notificationFormatter.visaWithdrawn({194 type: 'visaWithdrawn',195 withdrawnOn: '2000-01-01T12:00:00+09:00',196 shop: 'AMAZON CO JP',197 amount: 100000,198 number: '1A001001',199 })200 const text = message.attachments?.[0]?.text201 expect(text).toContain('100,000 支払いました。')202 expect(text).toContain('2000年1月1日(土) 12:00')203 })204 test('integration', async () => {205 await webhook.send(206 notificationFormatter.visaWithdrawn({207 type: 'visaWithdrawn',208 withdrawnOn: '2000-01-02T03:04:05+09:00',209 shop: 'AMAZON CO JP',210 amount: 100000,211 number: '1A001001',212 }),213 )214 })215 })...

Full Screen

Full Screen

provider.service.ts

Source:provider.service.ts Github

copy

Full Screen

...25 async sendItemCreationSuccess(26 item: Item,27 nickname: string28 ): Promise<IncomingWebhookResult> {29 return await this.webhook.send(30 ItemCreationSuccessTemplate.create(item, nickname)31 );32 }33 async sendItemCreationFail(34 url: string,35 nickname: string36 ): Promise<IncomingWebhookResult> {37 return await this.webhook.send(38 ItemCreationFailTemplate.create(url, nickname)39 );40 }41 async sendItemReport(42 item: Item,43 reason: string,44 nickname: string45 ): Promise<IncomingWebhookResult> {46 return await this.webhook.send(47 ItemReportTemplate.create(item, reason, nickname)48 );49 }50 async sendInquiryCreation(inquiry: Inquiry): Promise<IncomingWebhookResult> {51 return await this.webhook.send(InquiryCreationTemplate.create(inquiry));52 }53 async sendDigestCreation(digest: Digest): Promise<IncomingWebhookResult> {54 return await this.webhook.send(DigestCreationTemplate.create(digest));55 }56 async sendLookCreation(look: Look): Promise<IncomingWebhookResult> {57 return await this.webhook.send(LookCreationTemplate.create(look));58 }59 async sendVideoCreation(video: Video): Promise<IncomingWebhookResult> {60 return await this.webhook.send(VideoCreationTemplate.create(video));61 }62 async sendOldPayCancelRequested(63 merchantUid: string,64 input: CancelPaymentInput65 ): Promise<IncomingWebhookResult> {66 return await this.webhook.send(67 OldPaymentCancelRequestedTemplate.create(merchantUid, input)68 );69 }70 async sendContentReported(url: string): Promise<IncomingWebhookResult> {71 return await this.webhook.send(ContentReportedTemplate.create(url));72 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { webhooks } = require('qawolf');2const { createBrowser } = require('qawolf');3const browser = await createBrowser();4const page = await browser.newPage();5await webhooks.send({6 payload: { hello: 'world' },7});8await browser.close();9const { launch } = require('qawolf');10describe('test', () => {11 let browser;12 let page;13 beforeAll(async () => {14 page = await browser.newPage();15 });16 afterAll(async () => {17 await browser.close();18 });19 it('test', async () => {20 await page.click('[name="q"]');21 await page.type('[name="q"]', 'qawolf');22 await page.press('[name="q"]', 'Enter');23 await page.waitForSelector('text="QA Wolf: Automated browser tests for ...');24 await page.click('text="QA Wolf: Automated browser tests for ...');25 });26});27const { launch } = require('qawolf');28describe('test', () => {29 let browser;30 let page;31 beforeAll(async () => {32 page = await browser.newPage();33 });34 afterAll(async () => {35 await browser.close();36 });37 it('test', async () => {38 await page.click('[name="q"]');39 await page.type('[name="q"]', 'qawolf');40 await page.press('[name="q"]', 'Enter');41 await page.waitForSelector('text="QA Wolf: Automated browser tests for ...');42 await page.click('text="QA Wolf: Automated browser tests for ...');43 });44});45const { launch } = require('qawolf');46describe('test', () => {47 let browser;48 let page;49 beforeAll(async () => {50 page = await browser.newPage();51 });52 afterAll(async () => {53 await browser.close();54 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Webhook, MessageBuilder } = require('discord-webhook-node');2const embed = new MessageBuilder()3 .setTitle('Test')4 .setDescription('Test description')5 .setColor('#0099ff')6 .setTimestamp()7 .setFooter('Test footer')8 .addField('Test field', 'Test field value', true)9 .addField('Test field 2', 'Test field value 2', true)10 .addField('Test field 3', 'Test field value 3', false)11hook.send(embed);12module.exports = {13 testFramework: {14 },15 webhooks: {16 discord: {17 },18 },19};20{21 "scripts": {22 },23 "dependencies": {24 }25}

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2const qawolf = require("qawolf");3const qawolf = require("qawolf");4const qawolf = require("qawolf");5const qawolf = require("qawolf");6const qawolf = require("qawolf");7const qawolf = require("qawolf");8const qawolf = require("qawolf");9const qawolf = require("qawolf");10const qawolf = require("qawolf");11const qawolf = require("qawolf");12const qawolf = require("qawolf");13const qawolf = require("qawolf");

Full Screen

Using AI Code Generation

copy

Full Screen

1const {webhook} = require('qawolf');2await webhook.send({3 payload: {4 }5});6const {webhook} = require('qawolf');7await webhook.receive({8 payload: {9 }10});11const {webhook} = require('qawolf');12await webhook.send({13 payload: {14 }15});16const {webhook} = require('qawolf');17await webhook.receive({18 payload: {19 }20});21const {webhook} = require('qawolf');22await webhook.send({23 payload: {24 }25});26const {webhook} = require('qawolf');27await webhook.receive({28 payload: {29 }30});31const {webhook} = require('qawolf');32await webhook.send({33 payload: {34 }35});36const {webhook} = require('qawolf');37await webhook.receive({38 payload: {39 }40});41const {webhook} = require('qawolf');42await webhook.send({43 payload: {44 }45});46const {webhook} = require('qawolf');47await webhook.receive({48 payload: {49 }50});

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require('qawolf');2const { webhooks } = qawolf;3(async () => {4 await webhooks.send({5 payload: {6 },7 });8})();9{10 "scripts": {11 },12 "dependencies": {13 }14}15webhooks.send({16 payload: {17 json: { key: 'value' },18 },19});20qawolf test test.js --payload '{"text": "Hello World"}'21qawolf test test.js --payload '{"text": "Hello World"}' && node test.js22qawolf test test.js --payload '{"text": "Hello World"}' && node test.js23qawolf test test.js --payload '{"text": "Hello World"}' && node test.js

Full Screen

Using AI Code Generation

copy

Full Screen

1const { webhook } = require("qawolf");2const { send } = webhook;3send({4 data: { myData: "Hello" },5});6const { webhook } = require("qawolf");7const { send } = webhook;8send({9 data: { myData: "Hello" },10});11const { send } = require("qawolf");12send({13 data: { myData: "Hello" },14});15const { send } = require("qawolf");16send({17 data: { myData: "Hello" },18});19const { send } = require("qawolf");20send({21 data: { myData: "Hello" },22});

Full Screen

Using AI Code Generation

copy

Full Screen

1const QAWolf = require("@qawolf/webhook");2webhook.send("test");3const QAWolf = require("@qawolf/webhook");4const qawolf = new QAWolf.QAWolf();5qawolf.create("test");6const QAWolf = require("@qawolf/webhook");7const qawolf = new QAWolf.QAWolf();8qawolf.create("test");9npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { webhook } = require("qawolf");2const { webhook } = require("qawolf");3const data = {4}5const { webhook } = require("qawolf");6const data = {7}8const { webhook } = require("qawolf");9const data = {10}11});12const { webhook } = require("qawolf");13const data = {14}15}, {16});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful