Skip to content

Commit 923bb60

Browse files
Merge pull request #1 from seatplus/feature/corporation_member_tracking
Feature/corporation member tracking
2 parents bc258cb + 5c305f6 commit 923bb60

23 files changed

Lines changed: 655 additions & 94 deletions

.github/workflows/run-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
redis-version: 6 # optional, default is latest, was 5
2727
- name: Install Dependencies
2828
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
29+
- name: Run test & coverage
30+
run: vendor/bin/pest --coverage
2931
# - name: Test & publish code coverage
3032
# uses: paambaati/codeclimate-action@v2.6.0
3133
# env:

README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# :package_description
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/vendor_slug/package_slug.svg?style=flat-square)](https://packagist.org/packages/vendor_slug/package_slug)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/vendor_slug/package_slug/run-tests?label=tests)](https://github.com/vendor_slug/package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/vendor_slug/package_slug/Check%20&%20fix%20styling?label=code%20style)](https://github.com/vendor_slug/package_slug/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/vendor_slug/package_slug.svg?style=flat-square)](https://packagist.org/packages/vendor_slug/package_slug)
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/seatplus/telegram-channel.svg?style=flat-square)](https://packagist.org/packages/seatplus/telegram-channel)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/seatplus/telegram-channel/run-tests?label=tests)](https://github.com/seatplus/telegram-channel/actions?query=workflow%3Arun-tests+branch%3Amain)
5+
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/seatplus/telegram-channel/Check%20&%20fix%20styling?label=code%20style)](https://github.com/seatplus/telegram-channel/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/seatplus/telegram-channel.svg?style=flat-square)](https://packagist.org/packages/seatplus/telegram-channel)
77

88
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
99

@@ -33,12 +33,6 @@ TELEGRAM_REDIRECT_URI=http://yourdomain.tld/auth/telegram/callback
3333
```
3434
make sure to replace `yourdomain.tld` with your actual domain.
3535

36-
## Usage
37-
38-
```php
39-
$skeleton = new VendorName\Skeleton();
40-
echo $skeleton->echoPhrase('Hello, Spatie!');
41-
```
4236

4337
## Testing
4438

@@ -60,7 +54,7 @@ Please review [our security policy](../../security/policy) on how to report secu
6054

6155
## Credits
6256

63-
- [:author_name](https://github.com/:author_username)
57+
- [Herpaderp Aldent](https://github.com/herpaderpaldent)
6458
- [All Contributors](../../contributors)
6559

6660
## License

composer.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"name": "seatplus/telegram-channel",
3-
"description": ":package_description",
3+
"description": "implements notifications for telegram",
44
"keywords": [
5-
":vendor_name",
6-
"laravel",
7-
"package_slug"
5+
"seatplus",
6+
"telegram-channel"
87
],
98
"homepage": "https://github.com/seatplus/telegram-channel",
109
"license": "MIT",
@@ -15,17 +14,11 @@
1514
"role": "Developer"
1615
}
1716
],
18-
"repositories": [
19-
{
20-
"type": "path",
21-
"url": "../notifications"
22-
}
23-
],
2417
"require": {
2518
"php": "^8.0",
2619
"illuminate/contracts": "^8.37",
2720
"laravel-notification-channels/telegram": "^0.5.1",
28-
"seatplus/notifications": "*",
21+
"seatplus/notifications": "^0.1",
2922
"socialiteproviders/telegram": "^4.1.2"
3023
},
3124
"require-dev": {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up()
10+
{
11+
Schema::create('telegram_channels', function (Blueprint $table) {
12+
$table->bigInteger('id', true);
13+
$table->string('name');
14+
$table->timestamps();
15+
});
16+
}
17+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<template>
2+
<div
3+
:class="['text-gray-500 hover:text-gray-700','rounded-r-lg', 'group relative min-w-0 flex-1 overflow-hidden bg-white py-4 px-4 text-sm font-medium text-center hover:bg-gray-50 focus:z-10 cursor-pointer']"
4+
@click="open = !open"
5+
>
6+
<span>Create</span>
7+
<span
8+
aria-hidden="true"
9+
:class="['bg-transparent', 'absolute inset-x-0 bottom-0 h-0.5']"
10+
/>
11+
</div>
12+
<teleport to="#destination">
13+
<ModalWithFooter v-model="open">
14+
<template #symbol>
15+
<div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10">
16+
<svg
17+
class="h-6 w-6 text-green-600"
18+
fill="none"
19+
stroke="currentColor"
20+
viewBox="0 0 24 24"
21+
>
22+
<path
23+
stroke-linecap="round"
24+
stroke-linejoin="round"
25+
stroke-width="2"
26+
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
27+
/>
28+
</svg>
29+
</div>
30+
</template>
31+
<template #title>
32+
<span>Register a new Telegram Channel</span>
33+
</template>
34+
<template #description>
35+
<p class="text-sm text-gray-500">
36+
In order to send notifications to a channel, it must first be identified by the telegram bot. Please write <span class="text-gray-900 font-medium">/{{ randomString }}</span> in the channel you wish to register and click on the create button below.
37+
If the bot finds the said string, it will create a new tab.
38+
</p>
39+
</template>
40+
<template #buttons>
41+
<span class="flex w-full rounded-md shadow-sm sm:ml-3 sm:w-auto">
42+
<button
43+
type="button"
44+
class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 bg-green-600 text-base leading-6 font-medium text-white shadow-sm hover:bg-green-500 focus:outline-none focus:border-green-700 focus:ring-green transition ease-in-out duration-150 sm:text-sm sm:leading-5"
45+
@click="submit"
46+
>
47+
Create
48+
</button>
49+
</span>
50+
</template>
51+
</ModalWithFooter>
52+
</teleport>
53+
</template>
54+
55+
<script>
56+
import {ref} from "vue";
57+
import ModalWithFooter from "@/Shared/Modals/ModalWithFooter";
58+
import {Inertia} from "@inertiajs/inertia";
59+
import route from 'ziggy';
60+
61+
export default {
62+
name: "CreateTelegramChannel",
63+
components: {ModalWithFooter},
64+
emits: ['TelegramChannelCreated'],
65+
setup(props, {emit}) {
66+
const open = ref(false)
67+
const randomString = Math.random().toString(16).substr(2, 16);
68+
69+
const submit = () => Inertia.post(route('telegram.register.channels'),{id: randomString}, {
70+
onSuccess: () => {
71+
open.value = false
72+
emit('TelegramChannelCreated')
73+
}
74+
})
75+
76+
return {
77+
open,
78+
submit,
79+
randomString
80+
}
81+
}
82+
}
83+
</script>
84+
85+
<style scoped>
86+
87+
</style>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<template>
2+
<div :key="channel_results.length">
3+
<div class="sm:hidden">
4+
<label
5+
for="tabs"
6+
class="sr-only"
7+
>Select a tab</label>
8+
<select
9+
id="tabs"
10+
name="tabs"
11+
class="block w-full focus:ring-indigo-500 focus:border-indigo-500 border-gray-300 rounded-md"
12+
>
13+
<option
14+
v-for="tab in tabs"
15+
:key="tab.name"
16+
:selected="tab.current"
17+
>
18+
{{ tab.name }}
19+
</option>
20+
</select>
21+
</div>
22+
<div class="hidden sm:block">
23+
<nav
24+
class="relative z-0 rounded-lg shadow flex divide-x divide-gray-200"
25+
aria-label="Tabs"
26+
>
27+
<div
28+
v-for="(tab, tabIdx) in channels"
29+
:key="tab.name"
30+
:class="[tab.current ? 'text-gray-900' : 'text-gray-500 hover:text-gray-700', tabIdx === 0 ? 'rounded-l-lg' : '', 'group relative min-w-0 flex-1 overflow-hidden bg-white py-4 px-4 text-sm font-medium text-center hover:bg-gray-50 focus:z-10 cursor-pointer']"
31+
:aria-current="tab.current ? 'page' : undefined"
32+
@click="changeNotifiable(tab)"
33+
>
34+
<span>{{ tab.name }}</span>
35+
<span
36+
aria-hidden="true"
37+
:class="[tab.current ? 'bg-indigo-500' : 'bg-transparent', 'absolute inset-x-0 bottom-0 h-0.5']"
38+
/>
39+
</div>
40+
<CreateTelegramChannel @TelegramChannelCreated="fetchChannels()" />
41+
</nav>
42+
</div>
43+
</div>
44+
</template>
45+
46+
<script>
47+
import {computed, onBeforeMount, onMounted, onUpdated, ref, watch} from "vue";
48+
import route from 'ziggy';
49+
import CreateTelegramChannel from "./CreateTelegramChannel";
50+
51+
const tabs = [
52+
{ name: 'Private Notification', object: '#', current: true },
53+
{ name: 'Company', href: '#', current: false },
54+
{ name: 'Team Members', href: '#', current: false },
55+
{ name: 'Billing', href: '#', current: false },
56+
]
57+
58+
export default {
59+
name: "TelegramChannel",
60+
components: {CreateTelegramChannel},
61+
props: {
62+
modelValue: Object
63+
},
64+
emits: ['update:modelValue'],
65+
setup(props, {emit}) {
66+
67+
let channel_results = [];
68+
const channels = ref([])
69+
70+
const fetchChannels = async () => {
71+
await axios.get(route('telegram.get.channels'))
72+
.then(result => {
73+
channel_results =result.data
74+
mapChannels()
75+
})
76+
.catch(error => console.log(error))
77+
}
78+
const mapChannels = () => channels.value = _.chain(channel_results)
79+
.filter()
80+
.map(channel => (
81+
{
82+
...channel,
83+
current: _.isEqual(_.get(channel, 'notifiable'), props.modelValue)
84+
}
85+
))
86+
.value()
87+
88+
const changeNotifiable = (channel) => emit('update:modelValue', channel.notifiable)
89+
90+
watch(() => props.modelValue, () => mapChannels())
91+
92+
onMounted(() => {
93+
fetchChannels()
94+
})
95+
96+
return {
97+
tabs,
98+
channel_results,
99+
channels,
100+
fetchChannels,
101+
changeNotifiable
102+
}
103+
},
104+
}
105+
</script>
106+
107+
<style scoped>
108+
109+
</style>

resources/js/Pages/Notifications/TelegramIndex.vue

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,27 @@
5353

5454
<div
5555
v-else
56-
class="bg-white"
56+
class="space-y-3"
5757
>
58-
<div class="max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
59-
<div class="grid grid-cols-2 gap-8 md:grid-cols-6 lg:grid-cols-5">
60-
<NotificationComponent
61-
v-for="object in notifications"
62-
:key="object.title"
63-
:notification-object="object"
64-
:notifiable="notifiable"
65-
>
66-
<TelegramLogin v-show="!notifiable" />
67-
</NotificationComponent>
58+
<TelegramChannel
59+
v-if="canSubscribeToChannels"
60+
v-model="selectedNotifiable"
61+
/>
62+
<div
63+
:key="notifiable_id"
64+
class="bg-white"
65+
>
66+
<div class="max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
67+
<div class="grid grid-cols-2 gap-8 md:grid-cols-6 lg:grid-cols-5">
68+
<NotificationComponent
69+
v-for="object in notifications"
70+
:key="object.title"
71+
:notification-object="object"
72+
:notifiable="selectedNotifiable"
73+
>
74+
<TelegramLogin v-show="!notifiable" />
75+
</NotificationComponent>
76+
</div>
6877
</div>
6978
</div>
7079
</div>
@@ -80,10 +89,12 @@ import route from "ziggy";
8089
import * as SolidHeroIcons from '@heroicons/vue/outline'
8190
import NotificationComponent from "@/Shared/Notifications/Layout/NotificationComponent";
8291
import TelegramLogin from "./Telegram/TelegramLogin";
92+
import TelegramChannel from "./Telegram/TelegramChannel";
93+
import {computed, ref} from "vue";
8394
8495
export default {
8596
name: "TelegramIndex",
86-
components: {TelegramLogin, NotificationComponent, PageHeader, ...SolidHeroIcons},
97+
components: {TelegramChannel, TelegramLogin, NotificationComponent, PageHeader, ...SolidHeroIcons},
8798
props: {
8899
channels: {
89100
required: true,
@@ -101,17 +112,27 @@ export default {
101112
notifications: {
102113
required: true,
103114
type: Object
115+
},
116+
canSubscribeToChannels: {
117+
required: true,
118+
type: Boolean
104119
}
105120
},
106-
setup() {
121+
setup(props) {
122+
123+
const selectedNotifiable = ref(props.notifiable)
107124
108125
function visit(route_name) {
109126
return Inertia.visit(route(route_name))
110127
}
111128
129+
const notifiable_id = computed(() => _.get(selectedNotifiable.value, 'notifiable_id', new Date()))
130+
112131
return {
113132
pageTitle: 'Notifications: Telegram',
114-
visit
133+
visit,
134+
selectedNotifiable,
135+
notifiable_id
115136
}
116137
}
117138
}

routes/telegram.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@
1818
Route::get('/infos', [TelegramAuthController::class, 'infos'])->name('telegram.auth.infos');
1919
});
2020

21+
Route::prefix('/channels/')
22+
->group(function () {
23+
Route::get('', [TelegramNotificationController::class, 'getChannels'])->name('telegram.get.channels');
24+
Route::post('register', [TelegramNotificationController::class, 'registerChannel'])->name('telegram.register.channels');
25+
});
26+
2127
});
2228

0 commit comments

Comments
 (0)